温馨提示×

maven怎么排除parent依赖

小亿
759
2023-09-19 18:48:36
栏目: 编程语言

要排除Maven项目中的父依赖,你可以在子模块的pom.xml文件中使用标签,并使用元素指定父模块的路径。然后,在标签中排除不需要的依赖项。

下面是一个示例:

<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>child</artifactId>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>dependency</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>com.example</groupId>
<artifactId>excluded-dependency</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

在上面的示例中,标签指定了父模块的坐标和相对路径。然后,在标签中使用标签排除了不需要的依赖项。请确保在标签中使用正确的groupId和artifactId来排除相应的依赖项。

这样,当您构建子模块时,父模块的依赖不会被传递给子模块。

1