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用的true,这时B只能在A中使用,而不会主动传递到X中,X需要主动引用B才有B的依赖。
如果A不用true引用B,则会传递到X中,X如果不需要B则需要主动排除A传递过来的B。
<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
转载于:https://www.cnblogs.com/jakaBlog/p/11547401.html
相关资源:数据结构—成绩单生成器