In my maven project, I have added testng
with test
scope.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
I observed that class files from the guava
version which testng
depends on has ended up in my fat jar (I build the fat jar with maven-assembly-plugin
).
Guava
is not added directly as a dependency to my project, instead it is depended by protobuf-java-util
dependency which I have added in my project. What I have observed is that the guava class files included in the fat jar are from the guava version depended by testng
instead of the version depended by protobuf-java-util
When I excluded guava from testng
, I can observe that the correct version of guava
is picked up transitively from protobuf-java-util
.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
Note that the module I am observing this is a nested sub module two levels deep from the root pom, and the testng
dependency is in the root pom. I also observed that if I change the place which protobuf-java-util
dependency is added, it gets precedence over the version derived from testng
.
I also observed the same in the mvn:dependency-tree
output, where guava
is not shown under protobuf-java-util
but under testng
(with test
scope), and when I added the exclusion above, it is correctly shown under protobuf-java-util
.
What is the reason for this? From what I understood reading the documentation, the test
scoped dependencies are only for test execution, so I wouldn’t expect them to see in my fat jar.