Maven子模块怎么去掉父模块的包

1764
2023/10/10 18:46:38
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

要在Maven子模块中去掉父模块的包,可以使用<exclusions>元素来排除父模块的依赖包。

在子模块的pom.xml文件中,找到父模块的依赖,并在该依赖的<dependencies>元素中添加<exclusions>元素。在<exclusions>元素中,指定要排除的父模块的包的groupId和artifactId。

例如,以下是一个子模块的pom.xml文件的示例,其中排除了父模块的一个依赖包:

<project>
...
<parent>
<groupId>com.example</groupId>
<artifactId>parent-module</artifactId>
<version>1.0.0</version>
</parent>
...
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>parent-module-dependency</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>com.example</groupId>
<artifactId>excluded-dependency</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
...
</project>

在上面的示例中,parent-module-dependency是父模块的一个依赖包,通过在子模块的pom.xml文件中添加<exclusions>元素,并指定要排除的依赖包的groupIdartifactId,就可以在子模块中去掉父模块的该依赖包。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: maven本地有包但引不进来如何解决