Maven 2 Maven:在不同模块的pom.xml文件中使用依赖项标记
我正在开发一个maven应用程序。 我们有5个模块,因此作为应用程序的一部分,总共有6个pom.xml文件Maven 2 Maven:在不同模块的pom.xml文件中使用依赖项标记,maven-2,Maven 2,我正在开发一个maven应用程序。 我们有5个模块,因此作为应用程序的一部分,总共有6个pom.xml文件 <module>myware</module> <module>XMLModule</module> <module>Business</module> <module>Tests</module> <module>bayers</module> myware XML模
<module>myware</module>
<module>XMLModule</module>
<module>Business</module>
<module>Tests</module>
<module>bayers</module>
myware
XML模块
生意
测验
拜耳
对于所有这些模块,我提到了相对路径标记,以引用父pom.xml文件
如果许多模块都需要相同的jar文件,那么我们是否需要在每个pom.xml文件中提到这一点
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
公用记录
公用记录
1.1.1
罐子
编译
如果您依赖多个公共库,则可以创建另一个公共库
模块,该模块将这些列为依赖项,并依赖此模块来提取它们
以及物的方式。然而,这不是maven的最佳实践,而是
建议显式列出依赖项,而不要依赖可传递的
依赖关系。例如,请参见此示例
但是,您可以通过使用
父pom中的依赖项管理元素:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<!-- type and scope omitted since they use the default values -->
</dependency>
</dependencies>
</dependencyManagement>
如果您依赖于几个公共库,则可以创建另一个公共库 模块,该模块将这些列为依赖项,并依赖此模块来提取它们 以及物的方式。然而,这不是maven的最佳实践,而是 建议显式列出依赖项,而不要依赖可传递的 依赖关系。例如,请参见此示例 但是,您可以通过使用 父pom中的依赖项管理元素:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<!-- type and scope omitted since they use the default values -->
</dependency>
</dependencies>
</dependencyManagement>
还要注意,依赖关系是暂时的。所以,如果测试依赖于业务,那么它也将获得业务的所有编译/运行时依赖项。所以,如果测试依赖于业务,那么它也将获得业务的所有编译/运行时依赖项。