Issue
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
Solution
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 tojar
. 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 arejar
,war
,ejb-client
andtest-jar
New types can be defined by plugins that setextensions
totrue
, 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>
Answered By - Naman
Answer Checked By - Senaida (JavaFixing Volunteer)