Home > other >  How does the library dependency is inherited/works in maven?
How does the library dependency is inherited/works in maven?

Time:10-05

I have gradle scala project(Lets say "A") which uses the library(Lets say "X"). And i have used this Library-"X" in the build.gradle of Project-A as shown below and i'm using the Library-X classes to perform some operations.

build.gradle of Project-"A"

implementation "com.x.y.z.stone:central-dl-spark-common-integration-logging:0.4.0-SNAPSHOT"

Now Project-"A" is itself a library which is used in the Project-"B" and this Project-B is maven build. Now when i call the Project-A function which is acting as library in-turn uses Library-X function. But Project-B is complaining that class not found error as shown below. This is the Library-X class

java.lang.NoClassDefFoundError: com/x/y/z/integrationlogging/IntegrationLogging$

My question is do we even need to declare the Library-X in the pom.xml of Project-B as well?

CodePudding user response:

No: if Project-B imports Project-A, and Project-A has an internal dependency on Library-X, you usually don't need to do anything and it will resolve automatically.

Some exceptions may include conflicts and libraries that exist in a private nexus. For the former, you need to resolve the conflict in the pom.xml. For the latter, you need to make sure your repo is accessible from wherever you're compiling.

CodePudding user response:

No.

Dependencies are transitive "by default" unless the opposite is specificied (either with exclusions or scopes (a test scoped dependency won't be transitively propagated for instance)).

EDIT: you can use mvn dependency:tree to get a better understanding of your dependencies.

One possibility is that library X is pulled in different incompatible versions.

CodePudding user response:

Thank you for the having look at my post. By adding the Library-X under tag in the Project-B pom.xml, worked.Something shown below

<artifactSet>                           
<include>x.y.stone:central-dl-spark-common-integration-logging</include>
</artifactSet>
  • Related