Mr. Gung
Mr. Gung

Reputation: 163

Maven test-dependency removes transitive compile-dependency from uberjar

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!?

Upvotes: 2

Views: 95

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35785

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.

Upvotes: 2

Related Questions