You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决修改Maven依赖版本后触发的duplicate-finder-maven-plugin重复类检测报错

Fixing Duplicate Classes Error After Upgrading Interface-3 Version

Hey there, let's break down how to resolve this duplicate class issue you're hitting with the duplicate-finder-maven-plugin.

Why This Happens

When you upgraded Interface-3 to 1.1.NEW but kept Interface-1 and Interface-2 on 1.1, Maven is pulling in overlapping class files across these dependencies. This usually happens because:

  • The newer Interface-3 version includes classes that are already present in Interface-1/Interface-2 (1.1)
  • Or, the different versions are pulling in conflicting transitive dependencies that share duplicate classes

Step-by-Step Fixes

1. Identify Exactly Which Classes Are Duplicate

First, get a detailed report of the duplicate classes to target the problem accurately. Run this command in your project root:

mvn duplicate-finder:check -X

The verbose output will show you the full list of duplicate classes, along with which JAR files they come from. This is critical for deciding the next step.

2. Align Versions of Same-Group Dependencies (Best Practice)

Since all three dependencies share the same groupId (com.abc.interfaces), they're likely part of a cohesive set. Version mismatches here are a common source of conflicts. Try:

  • Upgrading Interface-1 and Interface-2 to 1.1.NEW to match Interface-3
    <dependency>
        <groupId>com.abc.interfaces</groupId>
        <artifactId>Interface-1</artifactId>
        <version>1.1.NEW</version>
    </dependency>
    <dependency>
        <groupId>com.abc.interfaces</groupId>
        <artifactId>Interface-2</artifactId>
        <version>1.1.NEW</version>
    </dependency>
    
  • If upgrading the other two isn't an option, revert Interface-3 back to 1.1 (if that's acceptable for your project needs)

3. Exclude Duplicate Classes/Transitive Dependencies

If you must keep the version mismatch:

  • Use the dependency:tree command to check for transitive dependency conflicts:
    mvn dependency:tree
    
  • If the duplicates come from transitive dependencies, add <exclusions> to the problematic dependency in your pom.xml. For example, if Interface-3 pulls in an older version of a library that Interface-1 already includes, exclude it:
    <dependency>
        <groupId>com.abc.interfaces</groupId>
        <artifactId>Interface-3</artifactId>
        <version>1.1.NEW</version>
        <exclusions>
            <exclusion>
                <groupId>[conflicting-group-id]</groupId>
                <artifactId>[conflicting-artifact-id]</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • As a last resort, you can configure the duplicate-finder-maven-plugin to ignore specific duplicate classes. Add this to your plugin configuration (note: this hides the issue rather than fixing it, so use sparingly):
    <plugin>
        <groupId>org.basepom.maven</groupId>
        <artifactId>duplicate-finder-maven-plugin</artifactId>
        <version>1.4.0</version>
        <configuration>
            <ignoredClasses>
                <ignoredClass>com.abc.interfaces.duplicate.ClassName</ignoredClass>
            </ignoredClasses>
        </configuration>
    </plugin>
    

Final Note

Sticking to consistent versions for dependencies in the same group is always the safest approach—it avoids most dependency-related headaches like this one.

内容的提问来源于stack exchange,提问作者Farhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 01:07:33