SoFunction
Updated on 2025-04-05

How to deal with maven dependency version conflict

maven dependency version conflict handling

Maven dependency version conflicts are generally caused by indirect dependencies to have multiple different versions of a jar package.

For example: A depends on version 1.0 of B, C depends on version 2.0 of B, and the project depends on version A and C, and indirectly depends on version 1.0 and 2.0 of B. At this time, two versions of B are introduced into the project. When there is a version conflict, ClassNotFoundException, NoSuchMethodError and other errors may occur.

To deal with version conflicts, you can use the following methods:

Method 1: Use exclusions to exclude dependencies

For example: We only rely on version 1.0 of B. At this time, we can exclude dependencies on B when dependent on C.

 <!-- exclude Spring Boot Dependency log package conflict -->
        <dependency>
            <groupId></groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId></groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Method 2: Use dependencyManagement to lock the version number

Usually, the parent project manages the dependency versions uniformly.

For example: We only rely on version 1.0 of B, and at this time, we can limit the version of B to 1.0 in the parent project.

	<packaging>pom</packaging>
	<properties>
        <>Hoxton.SR9</>
    </properties>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId></groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.