I am building a project that runs on top of Wildfly 14.0.1-Final.
I wanted to try the BOM feature of maven, so I thought: "I will add the wildfly 14 BOM to the dependency management of my parent POM, and then I will only need to define the groupId and artifactId of each artifact, without caring about version number/scope".
So, in my parent POM, I did add:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly</artifactId>
<version>14.0.1.Final</version>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
and to my children POM, I did add a reference to the CDI API:
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</dependency>
</dependencies>
Yet maven protests that it does not have the version for cdi-api.
The error is:
ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] 'dependencies.dependency.version' for javax.enterprise:cdi-api:jar is missing. @ line 29, column 15 @
I have also tried with the wildfly-javaee8
BOM artifact.
What am I missing/missunderstanding?
CodePudding user response:
@JamesR.Perkins comment made me realize that I did not have setup the import scope for the POM. Also, the correct artifact is org.wildfly.bom:wildfly-javaee8
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-javaee8</artifactId>
<version>14.0.1.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
James was right in that I need to define the scope as provided when I needed to use the dependency, otherwise it cdi-api.jar would end packaged in the ear and this could cause problems.
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
CodePudding user response:
When you add a dependency to the section of your parent POM, it sets a default version for that dependency, but it does not automatically add it to the dependencies section of your children POMs.
In your case, you need to add the for cdi-api to the section of your children POMs, not just in the section of your parent POM.
This should like this:
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>14.0.1.Final</version> <!-- version should match the version of wildfly BOM you are using -->
</dependency>
</dependencies>
Also, you can use wildfly-javaee8 BOM artifact instead of wildfly artifact that you are using, it covers all the dependencies you will need for your wildfly application development.
You can also check your wildfly documentation for more information on how to use BOM feature in wildfly.