Home > Enterprise >  Maven test-dependency removes transitive compile-dependency from uberjar
Maven test-dependency removes transitive compile-dependency from uberjar

Time:02-04

We have splunk-library-javalogging as compile-dependency and added com.squareup.okhttp3/okhttp as a test-dependency. okhttp is also a compile-dependency of the splunk-appender.

Using spring-boot-maven-plugin we realized the okhttp-Dependency is no longer included, when added as a test-dependency. Removing it, it is included again.

So it seems scoping okhttp as test overrides the transitive compile-dependency (excluding it from the jar) - and this doesn't feel correct!?

CodePudding user response:

This does not feel correct, but it is unfortunately the case.

Maven determines the scopes first, then creates the classpaths. And direct dependencies override transitive ones.

It would be smarter to create the compile classpath by just ignoring test scoped dependency entries, but this is not how Maven does it.

Quintessence: Only add a test dependency if the dependency is not already in mvn dependency:list.

  • Related