应用场景:projectA 依赖projectB, projectB 依赖projectC时
projectA中pom.xml
<groupId>com.cn.projectA</groupId>
<artifactId>projectA</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.cn.projectB</groupId>
<artifactId>projectB</artifactId>
<version>1.0B</version>
<!--方案一:使用execusions排除A与C的依赖 -->
<exclusions>
<exclusion>
<groupId>com.cn.projectC</groupId>
<artifactId>projectC</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
projectB中的pom.xml
<groupId>com.cn.projectB</groupId>
<artifactId>projectB</artifactId>
<version>1.0B</version>
<dependencies>
<dependency>
<groupId>com.cn.projectC</groupId>
<artifactId>projectC</artifactId>
<version>1.0C</version>
<!--依赖传递选项,默认为false为依赖,ture为不依赖传递
方案二:通过optional设置自动或手动,排除A与C的依赖
-->
<optional>false</optional>
</dependency>
</dependencies>
projectC的pom.xml
<groupId>com.cn.projectC</groupId>
<artifactId>projectC</artifactId>
<version>1.0C</version>
原文地址:https://blog.51cto.com/1929297/2401053
时间: 2024-10-16 13:36:42