maven exclude dependencies

By default, maven references all the jars it depends on. Sometimes the current project depends on different jars depending on different versions of some third-party jar packages. At this time, there will be dependencies on different versions of a jar file at the same time, and sometimes there will be dependency conflicts. The solution is to configure exclusion dependencies.
<dependency>   
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>2.5.6</version> 
     <exclusions> 
           <exclusion>     
                <groupId>commons-logging</groupId>         
                < artifactId>commons-logging</artifactId> 
           </exclusion> 
     </exclusions> 
</dependency>
      Note that exclusions are configured in a specific dependency, that is to say, to find the dependency path of the jar package to be excluded, this can be found in View the dependency graph of pom.xml in ide.

      Maven also has an optional dependency setting, which is optional for a dependency in the current project A setting, <optional>

    <groupId>sample.ProjectB</groupId>
    <artifactId>Project-B</artifactId>
    <version>1.0</version>
    <scope>compile</scope>
    <optional>true</optional>
</dependency>
      set like this Later, when another project X depends on A, if there is no class path in B in X, the B dependency will not be added.

Guess you like

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