Maven prohibits dependencies and filters dependencies

Everyone knows that the advantage of Maven is dependency management, especially the developers who used ANT in the early stage have a lot of feelings. Recently, I will develop a java project, and I will use maven. I will use hadoop and hbase clients. If a hadoop-client jar or hbase jar package is introduced, it will depend on more than a dozen other jar packages, and these jar packages I can't use the function of , so this kind of dependence has become the burden of engineering slimming. The key point is that I still have obsessive-compulsive disorder. When I see these packages that are useless for engineering, I go crazy. So I searched all over the Internet and found several methods:

1. Inter-project transfer

    If my current project is project1, project1 depends on project2, and <optional>true</optional> is added to the configuration of project1 depending on project2, indicating that the dependency is optional ,

<dependency><groupId>com.projecct</groupId><artifactId>project2</artifactId><version>1.0</version><scope>compile</scope><optional>true</optional></dependency>
  
  
  
  
  

 Then all the projects that declare to depend on project1 in the future must also write manual declarations if they also depend on project2. For example, project3 depends on project1 and project2. If project3 only declares the dependency on project1, then project2 will not automatically add the dependency, and the dependency on project2 needs to be re-declared.

This method cannot rule out other dependencies on the third-party jar package in my project, because it is impossible for me to modify the pom file of the third-party jar package, so it is only suitable for use within the project team.

2. Dependency filtering

(1) Single-dependent filtering

       Direct processing with dependency filtering: you can filter one or more, if you filter multiple, you need to write multiple <exclusion>. This can't solve my problem, or it's too troublesome to solve. I know that hbase depends on those packages, but I 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>  
</dependency>

(2) Multi-dependency filtering

     Filter all dependencies. Hands up and down ~ Ah, the world is quiet.

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325867839&siteId=291194637