这是我的父母 pom
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.fish56</groupId>
<artifactId>MavenModules</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>dao</module>
</modules>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</dependencyManagement>
这是我的子模块的 pom
<parent>
<artifactId>MavenModules</artifactId>
<groupId>com.github.fish56</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dao</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
我希望子模块可以继承父模块的依赖项,但失败了。
我无法在我的孩子 pom 中使用 lombok 或 junit。
这是我的文件树
.
├── dao
│ ├── pom.xml
│ ├── src
│ └── target
├── pom.xml
我认为应该有一种方法可以使某些依赖项成为所有模块的碎片,但我找不到解决方案。
在父级中POM
,之间的主要区别<dependencies>
and <dependencyManagement>
如下:
中指定的工件<dependencies>
部分将ALWAYS作为子模块的依赖项包含在内。
中指定的工件<dependencyManagement>
部分,将只被包括在内如果在子模块中也指定了它们<dependencies>
子模块本身的部分。
请在以下链接中找到更多信息:
dependencyManagement 和 Maven 中的依赖关系之间的区别 https://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)