1

Let's say B:1.0.1 has transitive dependency A:1.0.1, but the child project is supposed to depend on A:1.0.2 (with intentional overriding transitive dependencies).

It is easy to discover that the order of dependencies in <dependencyManagement> affect versions overriding, so adding A:1.0.2 in the child pom just before B:1.0.1 would force using A:1.0.2 even as a dependency for B:1.0.1.

In this case I'm looking for a way to declare A:1.0.2 in the parent pom, and remove boilerplate from all its children. Unfortunately, the following setup leads to using both versions in the final artifact: A:1.0.1 (comes as a dependency of B:1.0.1) and A:1.0.2 (comes from the explicit declaration in the parent pom).

How to force using version A:1.0.2 in all child projects, keeping the declaration in the parent?

Parent pom:

<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>

<dependencyManagement>
  <dependencies>   
    <dependency>
      <groupId>g</groupId>
      <artifactId>A</artifactId>
      <version>1.0.2</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

Child pom:

<parent>
  <groupId>my-group</groupId>
  <artifactId>my-parent</artifactId>
  <version>0.0.1</version>
</parent>

<artifactId>my-child</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>

<dependencies>   
  <dependency>
    <groupId>g</groupId>
    <artifactId>A</artifactId>
    <!-- version 1.0.2 comes from the parent pom -->
  </dependency>
</dependencies>

<dependencyManagement>
  <dependencies>   
    <dependency>
      <groupId>g</groupId>
      <artifactId>B</artifactId>
      <version>1.0.1</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
diziaq
  • 6,881
  • 16
  • 54
  • 96

1 Answers1

0

You are using the dependencyManagement incorrectly.

If A and B are jar artifacts, you should not have the tags

<type>pom</type>
<scope>import</scope>

These are for BOMs only.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Let's assume that the type is whatever is suitable for answering this question. Then how we solve this problem with versions conflict? – diziaq Mar 17 '21 at 08:41
  • Setting the version for A in the parent POM dependencyManagement will set the version for all child projects as well (unless, of course, they explicitly set their own version). – J Fabian Meier Mar 17 '21 at 09:09