A依赖于B,B依赖于C,A对C的依赖就是传递性的依赖 ,在A中引入B就会自动的引入C,但是可以通过在引入B的时候对C做一个排除依赖,但是要调用B对C有依赖的类或方法会报错:
<!-- A里引入B -->
<dependency>
<groupId>Black</groupId>
<artifactId>B</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 排除B对C的依赖,这样就不会引入C,但是要调用B对C有依赖的类或方法会报错 -->
<exclusions>
<exclusion>
<groupId>Black</groupId>
<artifactId>C</artifactId>
</exclusion>
</exclusions>
</dependency>
C的pom文件(这个不重要):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Black</groupId>
<artifactId>C</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>C</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
</project>
B的pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Black</groupId>
<artifactId>B</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>B</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<!-- B里引入C -->
<dependency>
<groupId>Black</groupId>
<artifactId>C</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
A的pom文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Black</groupId>
<artifactId>A</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>A</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<!-- A里引入B -->
<dependency>
<groupId>Black</groupId>
<artifactId>B</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 排除B对C的依赖,这样就不会引入C,但是调用B对C有依赖的类或方法会报错 -->
<exclusions>
<exclusion>
<groupId>Black</groupId>
<artifactId>C</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>