从Bitbucket克隆项目配置Tomcat后,Maven安装找不到Artifact如何解决?
先看看你遇到的错误详情:
[INFO] --- maven-dependency-plugin:2.10:copy (default) @ authconfig
[INFO] Configured Artifact: ch.smartlink:authconfig:0.0.1-SNAPSHOT:jar
Downloading: http://central.maven.org/maven2/ [...private link]
Downloading: http://central.maven.org/maven2/ [...private link]
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:copy (default) on project authconfig: Unable to find artifact. Could not find artifact ch.smartlink:authconfig:jar:0.0.1-SNAPSHOT in nexus (http://central.maven.org/maven2/)
[ERROR] Try downloading the file manually from the project website.
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=ch.smartlink -DartifactId=authconfig -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=... -DartifactId=authconfig -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR] ...:authconfig:jar:0.0.1-SNAPSHOT
[ERROR] from the specified remote repositories:
[ERROR] nexus (http://central.maven.org/maven2/, releases=true, snapshots=true)
这种问题本质是这个authconfig是你们内部的快照依赖,Maven中央仓库根本没有它,给你几个可行的解决步骤:
1. 检查并添加公司内部的快照仓库配置
Maven默认只去中央仓库找依赖,但内部项目的快照包肯定存在你们公司自己的Nexus/Artifactory仓库里。你需要修改Maven的配置文件:
- 找到你的Maven
settings.xml文件(一般在用户目录下的.m2文件夹里,或者Maven安装目录的conf文件夹) - 在文件里添加你们公司的快照仓库配置,示例如下:
<repositories> <repository> <id>company-internal-snapshots</id> <url>http://your-company-nexus-url/repository/snapshots-repo/</url> <snapshots> <enabled>true</enabled> <!-- 如果需要自动更新快照,可添加此项 --> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> - 保存配置后,重新执行
mvn install,Maven就会从内部仓库尝试拉取这个快照包了
2. 手动将jar包安装到本地Maven仓库
如果内部仓库暂时没有这个包,或者你暂时无法访问内部仓库,可以手动安装:
- 先获取到
authconfig-0.0.1-SNAPSHOT.jar文件:要么从Bitbucket克隆authconfig项目自己编译(进入项目目录执行mvn clean install),要么找同事要编译好的jar包 - 执行以下Maven命令,把jar包安装到本地仓库:
mvn install:install-file -DgroupId=ch.smartlink -DartifactId=authconfig -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/your/authconfig-0.0.1-SNAPSHOT.jar - 替换命令里的
/path/to/your/为你实际的jar文件路径,执行完成后再跑mvn install,依赖就能被本地仓库提供了
3. 如果你是authconfig项目的开发者
直接先处理authconfig项目:
- 切换到
authconfig项目的根目录 - 执行
mvn clean install,把这个快照包安装到本地Maven仓库 - 回到当前项目,再执行
mvn install即可正常引用
内容的提问来源于stack exchange,提问作者Dũng Nguyễn Văn




