2

项目 A 依赖于具有运行时范围的项目 B。项目 B 依赖于具有编译范围的项目 C。如果项目 A 中的代码调用项目 C 中的函数,我希望项目 A 的 mvn compile 会失败,但事实并非如此。

预期的行为是什么?

我将 maven 3.0.4 与 maven-compiler-plugin 2.5.1 和 maven-dependency-plugin 2.5 一起使用。

4

1 回答 1

3

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

于 2013-04-04T22:26:50.620 回答