MAVEN relies on excluding methods that rely on transitive cancellation dependencies

Source: Internet
Author: User

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 ,

<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.

<dependency>         <groupId>org.apache.hbase</groupId>     <artifactid>hbase</ artifactid>     <version>0.94.17</version>      <exclusions>             <exclusion>                      <groupId>commons-logging</groupId>                          <artifactId>commons-logging</artifactId>             </exclusion>       </exclusions>  

(2) Multi-dependency filtering

So the dependence has been filtered. The world is quiet with a knife in his hand.

<dependency><groupId>org.apache.hbase</groupId><artifactId>hbase</artifactId> <version>0.94.17</version><exclusions><exclusion><groupId>*</groupId>< Artifactid>*</artifactid></exclusion></exclusions></dependency>

Since the control of this dependency filter ah, my waist is not sour, leg pain, hands do not shake, breath ah, 5000 lines of code, do not feel tired ~! Look here! Look here! Look where it is! If you want to rely on it there! Mother no longer have to worry about my study!



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MAVEN relies on excluding methods that rely on transitive cancellation dependencies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.