maven package conflicts

  The indirect reference of maven will introduce other undeclared packages, maven's own conflict resolution, and the final referenced package may not be the desired version.

  

  By directly declaring the desired version number, there is no indirection problem.

  When there are many submodules, you can use dependencyManagement to manage them uniformly in the parent module.

  Configuration in parent module:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>1.2.3.RELEASE</version>
            </dependency>
        </dependencies>
</dependencyManagement>

  Submodules do not need to specify version information:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

  What is defined in dependencyManagement is only the declaration of dependencies, and does not implement import, so sub-projects need to explicitly declare the dependencies to be used.

 

  When a problem caused by a package conflict such as ClassNotFoundException occurs, it can be solved as follows:

  Reimport in intellj will re-download the corresponding package to solve the problem of IDE cache.

  

  When there is still a conflict, use the mvn dependency:tree command to view the source of the indirect import.

  

  mvn dependency:tree finds which package of which module indirectly introduces the package with the problematic version, and uses exclusion to cut off the reference relationship. 

<dependency>  
    <groupId>org.unitils</groupId>  
    <artifactId>unitils-dbmaintainer</artifactId>  
    <version>${unitils.version}</version>  
    <exclusions>   
        <exclusion>  
            <artifactId>asm</artifactId>  
            <groupId>asm</groupId>  
        </exclusion>  
    </exclusions>  
</dependency>

 

Guess you like

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