Aliaksei
Aliaksei

Reputation: 1447

Maven dependency with type = pom

I declare in the parent POM

<dependencyManagement>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
            <scope>compile</scope>
        </dependency>
</dependencyManagement>

Further, the child pom use

<dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
</dependencies>

All work fine? but when I use such dependency with type = pom

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-7.0</artifactId>
                <version>${jboss-javaee-7.0.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
</dependencyManagement>

I have error

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project by.services:by.utils:1.0.2 (D:\Work\V2_Change_Maven_Structure\by.utils\pom.xml) has 1 error
[ERROR]     'dependencies.dependency.version' for org.jboss.spec:jboss-javaee-7.0:jar is missing. @ line 18, column 21
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

How to declare a dependency in dependencyManagement with type = pom $ {Jboss-javaee-7.0.version} announced If I bear jboss-javaee-7.0 in the root, then runs

Upvotes: 6

Views: 25258

Answers (2)

Naman
Naman

Reputation: 31868

The clarification here is that when you do not define <type> on your </dependency> within </dependencyManagement> it defults to jar

<dependencyManagement>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons-lang3.version}</version>
        <scope>compile</scope>
        <type>jar<type> <!--default value-->
    </dependency>
</dependencyManagement>

and hence the module uses that jar while using it as

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
</dependency> 

The type of dependency. This defaults to jar. While it usually represents the extension on the filename of the dependency, that is not always the case. A type can be mapped to a different extension and a classifier. The type often corresponds to the packaging used, though this is also not always the case. Some examples are jar, war, ejb-client and test-jar New types can be defined by plugins that set extensions to true, so this is not a complete list.


But next when you explicitly declare the parent pom to have the type as

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-7.0</artifactId>
            <version>${jboss-javaee-7.0.version}</version>
            <type>pom</type><!--override the default value-->
            <scope>import</scope>
        </dependency>
</dependencyManagement>

the child module now either can inherit the dependency with the same <type> as

<dependency>
     <groupId>org.jboss.spec</groupId>
     <artifactId>jboss-javaee-7.0</artifactId>
     <type>pom</type><!--inherited-->
</dependency>

OR if you want to utilize the jar of the project which is a different <type>, you can explicitly mention the dependency as :

<dependency>
     <groupId>org.jboss.spec</groupId>
     <artifactId>jboss-javaee-7.0</artifactId>
     <version>${jboss-javaee-7.0.version}</version>
     <type>jar</type> <!--different from parent-->
</dependency>

Upvotes: 12

ravthiru
ravthiru

Reputation: 9623

You are trying to import jboss-javaee-7.0 jar in your child project, there is no such jar, it is of type pom which you already importing in your parent.

You need to import dependencies of jboss-javaee-7.0 in your child project, some thing like.

<dependency>
    <groupId>org.jboss.spec.javax.ws.rs</groupId>
    <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
</dependency>

You can get more information about importing dependencies

Upvotes: 2

Related Questions