Dominik Reinert
Dominik Reinert

Reputation: 895

Why is my Maven not using the defined BOM?

I am currently trying to introduce a BOM (bill of materials) file to my Maven project, but it does not seem to work and I have no clue, why.

This is my bom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.private</groupId>
  <artifactId>test.bom</artifactId>
  <version>5.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
    <version.CoreAnnotation>5.0.0-SNAPSHOT</version.CoreAnnotation>
    <version.CoreWeb>5.0.0-SNAPSHOT</version.CoreWeb>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.private</groupId>
        <artifactId>CoreAnnotation</artifactId>
        <version> ${version.CoreAnnotation}</version>
        <type>ejb</type>
      </dependency>
      <dependency>
        <groupId>com.private</groupId>
        <artifactId>CoreWeb</artifactId>
        <version>${version.CoreWeb}</version>
        <type>war</type>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

There are many more, but I excluded them because I think this should be enough as an example.

This is my pom (where I try to include the bom):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>Core</artifactId>
    <groupId>com.private</groupId>
    <version>5.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>Core-ear</artifactId>
  <packaging>ear</packaging>
  <name>Core-ear: EAR Module for private</name>

  <properties>
    <version.test.bom>5.0.0-SNAPSHOT</version.test.bom>
  </properties>


  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.private</groupId>
        <artifactId>test.bom</artifactId>
        <version>${version.test.bom}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

Whenever I use maven install there should be a collection of all packages defined in the dependencies section appear in the folder \target\Core-ear\

Now the problem: The dependencies defined in the bom don't appear there. What could be the problem?

ps: running mvn install -X for debugging does not seem to help.

Upvotes: 1

Views: 1380

Answers (1)

Tunaki
Tunaki

Reputation: 137084

This happens because you did not declare the dependencies in your POM. You only declared the <dependencyManagement> section.

In your POM, you need to add the following dependencies, without the version:

<dependencies>
  <dependency>
    <groupId>com.private</groupId>
    <artifactId>CoreAnnotation</artifactId>
    <type>ejb</type>
  </dependency>
  <dependency>
    <groupId>com.private</groupId>
    <artifactId>CoreWeb</artifactId>
    <type>war</type>
  </dependency>
</dependencies>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.private</groupId>
      <artifactId>test.bom</artifactId>
      <version>${version.test.bom}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

Refer to Introduction to the Dependency Mechanism: BOM are used to factor version of all the artifacts, so you don't need to add it in your <dependency> section.

Upvotes: 2

Related Questions