# com.google.guava:guava:jar:30.1-jre 的依赖收敛错误，依赖路径为：

- **ID:** `java/maven-enforcer-dependency-convergence`
- **领域:** java
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Maven 3.8 | active | — | — |
| Maven 3.9 | active | — | — |
| maven-enforcer-plugin 3.0.0 | active | — | — |
| maven-enforcer-plugin 3.1.0 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **Remove the enforcer plugin entirely from the pom.xml** — This suppresses the build error but leaves the classpath with multiple versions, which can cause NoSuchMethodError or ClassCastException at runtime. (90% 失败率)
- **Manually exclude all conflicting transitive dependencies one by one** — This is tedious and error-prone; missing one exclusion still causes the error. It's better to use dependency management. (70% 失败率)
- **Use the latest version of the dependency in all places** — Simply using the latest version may introduce breaking changes from incompatible APIs; requires careful testing. (60% 失败率)
