java build_error ai_generated true

无法为项目 com.example:my-app:jar:1.0.0 解析依赖:在中央仓库 (https://repo.maven.apache.org/maven2) 中找不到工件 com.example:missing-lib:jar:2.0.0

Could not resolve dependency for project com.example:my-app:jar:1.0.0: Could not find artifact com.example:missing-lib:jar:2.0.0 in central (https://repo.maven.apache.org/maven2)

ID: java/maven-dependency-not-found

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-03-15首次发现

版本兼容性

版本状态引入弃用备注
8+ active

根因分析

依赖工件未发布到配置的仓库,或仓库 URL 不正确。

English

The dependency artifact is not published to the configured repositories, or the repository URL is incorrect.

generic

解决方案

  1. 95% 成功率 Add the correct repository to pom.xml
    <repositories><repository><id>my-repo</id><url>https://my-company.com/repo</url></repository></repositories>
  2. 90% 成功率 Install the dependency manually using mvn install:install-file
    mvn install:install-file -Dfile=missing-lib-2.0.0.jar -DgroupId=com.example -DartifactId=missing-lib -Dversion=2.0.0 -Dpackaging=jar

无效尝试

常见但无效的做法:

  1. Adding a random third-party repository without verifying its contents 90% 失败

    The repository may not contain the artifact, or it could be malicious.

  2. Cleaning the local Maven repository (~/.m2/repository) without verifying the remote 85% 失败

    If the artifact is not in any remote repo, cleaning the local cache doesn't help.