We all know that Maven has the advantage of relying on management, especially the early use of ant developers have a lot of feelings. Recently to develop a Java project, to use MAVEN, will use the Hadoop and HBase clients, and introduce a hadoop-client jar or hbase jar package, will rely on more than 10 other jar package, and these jar package function I do not use, So this dependence has become the weight of the project. The key I have obsessive-compulsive disorder, I am crazy to see these bags that are useless to the project. So in the online hundred find Chihiro, found a few ways:
1. Inter-project Transfer
If my current project is project1,project1 to rely on Project2,project1 dependent project2, add <optional>true</optional> to the configuration that is dependent on the optional ,
Java code
- <dependency>
- <groupId>com.projecct</groupId>
- <artifactId>project2</artifactId>
- <version>1.0</version>
- <scope>compile</scope>
- <optional>true</optional>
- </dependency>
Then all the items that are declared dependent on Project1 will have to be written manually if they are also dependent on project2. For example, PROJECT3 relies on Project1 and Project2, if Project3 only declares a dependency on Project1, then Project2 does not automatically join the dependency and needs to re-declare its dependency on Project2.
This approach excludes other dependencies that my project has on third-party jar packages because I cannot modify the pom files of third-party jar packages, so it is only suitable for use within a project group.
2. Dependency filtering
(1) Single-dependency filtering
With dependency filtering direct processing: You can filter one or more, if filtering multiple to write multiple <exclusion>. This will not solve my problem, or solve too much trouble, I know that hbase depends on those packages, can't remember.
Java code
- <dependency>
- <groupId>org.apache.hbase</groupId>
- <artifactId>hbase</artifactId>
- <version>0.94. </version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
(2) Multi-dependency filtering
So the dependence has been filtered. The world is quiet with a knife in his hand.
Java code
- <dependency>
- <groupId>org.apache.hbase</groupId>
- <artifactId>hbase</artifactId>
- <version>0.94. </version>
- <exclusions>
- <exclusion>
- <groupId>*</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
MAVEN relies on excluding methods that rely on transitive cancellation dependencies