Different uses of the same artifact and transitive dependencies
I have a project A that uses library L v1.0.0 with a testing scope. Project A also depends on project B (with scope compilation), with B transitively dependent on library L v1.0.0 (with scope compilation).
Why is the final library area L for project A a "test"? This throws me a NotClassDefFoundError at runtime. It seems that the definition of project A dependencies of library L overrides the definitions of transitive dependencies on L.
What's wrong here? My project A only uses L for unit tests, so I define a dependency with the "test" scope. But in the end, I want L to be on my classpath, since project A depends on project B for production, and B needs (transitively) the library L.
Thanks for helping me
source to share
Are you using Maven? In this case, if I recall correctly, Maven will use the "closest" definition to determine the actual scope. In this case, module A specifies the test, and the transitive scope from B is redefined since A is the closest since you are actually in A :) This gets complicated when you have multiple modules with dependencies between them. A common facility is to define all dependencies (and scopes and versions) in a common parent Pom.xml in a tag <dependencyManagement>
.
source to share