java build_error ai_generated true

Dependency convergence error for com.google.guava:guava:jar:30.1-jre paths to dependency are:

ID: java/maven-enforcer-dependency-convergence

Also available as: JSON · Markdown · 中文
88%Fix Rate
87%Confidence
1Evidence
2023-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Maven 3.8 active
Maven 3.9 active
maven-enforcer-plugin 3.0.0 active
maven-enforcer-plugin 3.1.0 active

Root Cause

Multiple versions of the same dependency (e.g., Guava) are resolved in the dependency tree with different versions, violating the Maven Enforcer plugin's dependency convergence rule, which requires a single version per artifact.

generic

中文

依赖树中解析了同一依赖(例如 Guava)的多个版本,违反了 Maven Enforcer 插件的依赖收敛规则,该规则要求每个工件只有一个版本。

Official Documentation

https://maven.apache.org/enforcer/enforcer-rules/dependencyConvergence.html

Workarounds

  1. 90% success Add a <dependencyManagement> section in the parent pom.xml to force a specific version of the conflicting artifact. Example: <dependencyManagement> <dependencies> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>31.1-jre</version> </dependency> </dependencies> </dependencyManagement>
    Add a <dependencyManagement> section in the parent pom.xml to force a specific version of the conflicting artifact. Example:
    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>31.1-jre</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
  2. 85% success Use the Maven Enforcer plugin's dependencyConvergence rule with excludes for known unavoidable conflicts: <execution> <id>enforce</id> <configuration> <rules> <dependencyConvergence> <excludes> <exclude>com.google.guava:guava</exclude> </excludes> </dependencyConvergence> </rules> </configuration> </execution>
    Use the Maven Enforcer plugin's dependencyConvergence rule with excludes for known unavoidable conflicts:
    <execution>
      <id>enforce</id>
      <configuration>
        <rules>
          <dependencyConvergence>
            <excludes>
              <exclude>com.google.guava:guava</exclude>
            </excludes>
          </dependencyConvergence>
        </rules>
      </configuration>
    </execution>
  3. 80% success Run 'mvn dependency:tree' to identify all paths and then add explicit <exclusions> in the specific dependency that brings the unwanted version.
    Run 'mvn dependency:tree' to identify all paths and then add explicit <exclusions> in the specific dependency that brings the unwanted version.

中文步骤

  1. Add a <dependencyManagement> section in the parent pom.xml to force a specific version of the conflicting artifact. Example:
    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>31.1-jre</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
  2. Use the Maven Enforcer plugin's dependencyConvergence rule with excludes for known unavoidable conflicts:
    <execution>
      <id>enforce</id>
      <configuration>
        <rules>
          <dependencyConvergence>
            <excludes>
              <exclude>com.google.guava:guava</exclude>
            </excludes>
          </dependencyConvergence>
        </rules>
      </configuration>
    </execution>
  3. Run 'mvn dependency:tree' to identify all paths and then add explicit <exclusions> in the specific dependency that brings the unwanted version.

Dead Ends

Common approaches that don't work:

  1. Remove the enforcer plugin entirely from the pom.xml 90% fail

    This suppresses the build error but leaves the classpath with multiple versions, which can cause NoSuchMethodError or ClassCastException at runtime.

  2. Manually exclude all conflicting transitive dependencies one by one 70% fail

    This is tedious and error-prone; missing one exclusion still causes the error. It's better to use dependency management.

  3. Use the latest version of the dependency in all places 60% fail

    Simply using the latest version may introduce breaking changes from incompatible APIs; requires careful testing.