免责声明
(我最初在这里以非常详细的方式提出了这个问题。我在这里maven-users
摘录了它,因为邮件列表已经对这个问题保持沉默。)(不仅仅是另一个新手问题)
参考
我的参考资料是 http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management;如果这已过时或错误,请在此讨论中告诉我。
问题
该文档中有一节以“第二个,非常重要......”开头。在下文中,我将参考该部分的项目A
和B
,并将从中摘录。
在该部分中,您将看到该项目A
有一个<dependencyManagement>
部分 - 除其他外 - 将工件定义c
为具有范围compile
:
<!-- In A's pom.xml; condensed for brevity -->
<dependencyManagement>
<dependency>
<groupId>test</groupId>
<artifactId>c</artifactId>
<version>1.0</version>
<scope>compile</scope> <!-- look: compile scope -->
</dependency>
</dependencyManagement>
然后你会看到一个pom.xml
for 项目B
,它 (a) 从 project 继承A
(因此继承了它的dependencyManagement
部分)并且 (b) 建立了对 artifact 的依赖c
,而不必指定它的version
. 您还会注意到对 artifact 的依赖c
覆盖了c
to be的范围,runtime
而不是compile
:
<!-- In B's pom.xml, whose parent is A's pom.xml (above); condensed for brevity -->
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>c</artifactId>
<scope>runtime</scope> <!-- look: runtime scope -->
</dependency>
</dependencies>
同样,您会注意到没有<version>
元素,但有一个<scope>runtime</scope>
元素。
我对此的解释是,当一切都说完了,B
将取决于范围内1.0
的工件版本c
,runtime
而不是compile
范围。
那是对的吗?我的maven-ear-plugin
错误在于这是预期的行为这一事实。maven-ear-plugin
构建.ear
文件时不会发生这种情况。
接下来,如果这是正确的,我还希望如果工件c
具有任何传递runtime
依赖项,它们将在B
的runtime
类路径中可用(如http://maven.apache.org/guides/introduction/introduction- to-dependency-mechanism.html#Dependency_Scope)。
那是对的吗?