Bob Shur
Bob Shur

Reputation: 21

maven runtime scope but transitive dependencies have compile scope

Project A depends on project B with runtime scope. Project B depends on project C with compile scope. If code in project A calls a function in project C, I would expect mvn compile of project A to fail, but it does not.

What is the expected behavior?

I am using maven 3.0.4 with maven-compiler-plugin 2.5.1 and maven-dependency-plugin 2.5.

Upvotes: 2

Views: 2753

Answers (1)

Stephen Connolly
Stephen Connolly

Reputation: 14116

The maven documentation gives a slightly confusing until you understand it table.

To work out what the scope is you need to follow the following path of entries...

  1. Start from the ultimate parent project and merge all the <dependencies> list. Do the same for <dependencyManagement>. When merging, the groupId:artifactId:type:classifier is the key, child poms which have dependencies with the same key overwrite whatever values they specify.

  2. Now you need to apply the <dependencyManagement> to the <dependencies> list to fill in any blanks.

At this point we now know the dependencies of the current project. The scopes in this list correspond to the row you select from the table.

For each dependency in the list, you repeat the above process to compute the dependencies effective dependency list (yes including ths step too) and then the scope of these dependencies correspond with the column selection in the table.

Once you have worked out the transitive dependencies, and their scopes via the table, for each dependency, you then apply the current module's <dependencyManagement> overriding scope, version and exclusions as defined by <dependencyManagement> and there you have the effective transitive dependency list.

There are other more subtle effects which are there to retain existing behaviour where bugs have essentially become features, and version ranges can further confuse things, but above shoud give a god general understanding of the problem space

Upvotes: 3

Related Questions