sgalenski
sgalenski

Reputation: 181

Maven Classloading Order

i have a question about the classloading order with maven.

I know, since maven version 2.0.9 the classloading has been deterministic an uses the order in the pom. I am not clear about the transitive dependencies. Does maven load all top level dependencies first and then the transitive dependencies. Or load a top level dependencies with all transitive dependencies and then load the next top level dependency.

I know in a fully correct maven setup there is no problem with the order but I have some duplicated classes in a dependency and I want to know which one is used. Excluding the transitive dependency is no option, because not all classes are covered in both jars.

For example: My project has three dependencies A, B and C. A has a transitive dependency to C. Which is the maven order to load the dependencies?

POM:

Case A:

A --> B --> C

Case B: A --> (transitive dependency) C --> B --> C

Thank you

Upvotes: 1

Views: 1903

Answers (1)

sgalenski
sgalenski

Reputation: 181

I have checked the classpath with the debug option -X and classpath correspond to case b.

The first dependency entry (A) is loaded on the classpath with its transitive dependencies (C). Then the next pom entry is loaded (B).

I hope other users can verify my solution.

Upvotes: 1

Related Questions