0

I deployed a jar A with the following dependency:

<dependency>
  <groupId>io.projectreactor</groupId>
  <artifactId>reactor-core</artifactId>
  <version>3.3.1.RELEASE</version>
</dependency>

I have another project B and project C both with dependency to A. So the structure is as following:

B -> A -> reactor-core

C -> A -> reactor-core

The problem is the version of reactor-core is different in project B and project C. In B, its version is 2.0.8. In C it's 3.3.1 . In fact, I have excluded the version 2.0.8 in project A. I don't know why it still appears.

ysfseu
  • 666
  • 1
  • 10
  • 20

1 Answers1

2

Don't use excludes. They are hard to manage.

Look at the dependency tree (mvn dependency:tree). You will reactor-core at different places with different versions. Maven "mediates" this tree and chooses the "nearest" version.

If you don't want this behaviour (actually, you often don't want that), make an entry in <dependencyManagement> with the correct version. This will override all transitive versions and you get the version you want. You do not need exclusions for that.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Hi, I have add with the correct version to project A. But when B has dependency to jar A. the version is still 2.0.8. Do you know how to make the deployed jar have the correct version? – ysfseu Jan 14 '20 at 12:33
  • The dependencyManagement overrides all transitive versions. Where exactly does the 2.0.8 come from? From a parent POM? – J Fabian Meier Jan 14 '20 at 12:57
  • In A, there is a dependency rsocket-core, which has a transitive dependency to version 2.0.8 – ysfseu Jan 14 '20 at 13:09
  • You need to add ` io.projectreactor reactor-core 3.3.1.RELEASE ` to the dependencyManagement of B. – J Fabian Meier Jan 14 '20 at 13:14
  • yes, this will work. But I don't want any project that depends on A to add this dependencyManagement. How can I ensure that A contains only version 3.3.1? – ysfseu Jan 15 '20 at 03:59
  • If A has a direct dependency on 3.3.1, then this will override all transitive dependencies of A. – J Fabian Meier Jan 15 '20 at 06:20
  • Maybe we are missing something important in your POM here. Because if B depends on A and A has a direct dependency on reactor-core:3.3.1, then B will have a dependency on reactor-core:3.3.1 unless B has another dependency D that depends on a different reactor-core version or B has some dependencyManagement that overrides this. – J Fabian Meier Jan 15 '20 at 07:48