maven 中 Optional和Exclusions的区别
maven 中 Optional和Exclusions的区别
区别
- Optional:该依赖只能在本模块/项目中中传递,不会传递到引用该项目的父项目中,父项目需要主动引用该依赖才行。
- Exclusion:主动排除子项目传递过来的依赖。
用法区别:
Project-X -> Project-A Project-A -> Project-B
<project>
...
<dependencies>
<!-- declare the dependency to be set as optional -->
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<optional>true</optional> <!-- value will be true or false only -->
</dependency>
</dependencies>
</project>
如上X依赖A,A依赖B用的
如果A不用
<project>
...
<dependencies>
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
官方文档 http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html