Maven 3.8.2如何运行从第三方私有仓库下载的插件
问题根本原因
你遇到的问题是Maven 3.x的增强本地仓库管理器的校验逻辑导致的:正式发布版本(RELEASE/RC)的构件会在本地记录下载来源仓库,你运行插件时Maven默认仅加载中央仓库,发现该构件不是从中央仓库下载的,哪怕本地文件存在也会判定为不可用。而SNAPSHOT版本属于动态更新版本,Maven不会做严格的来源校验,所以可以正常运行。
解决方案
方案1:全局配置私有插件仓库(一劳永逸)
你之前的认知有误,~/.m2/settings.xml完全支持配置全局插件仓库,不需要依赖项目POM文件,添加如下配置即可:
<settings> <!-- 保留原有配置 --> <profiles> <profile> <id>private-repos-global</id> <pluginRepositories> <pluginRepository> <id>excelfore.private</id> <url>https://你的私有仓库地址</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-- 激活上述配置,全局生效 --> <activeProfiles> <activeProfile>private-repos-global</activeProfile> </activeProfiles> <!-- 如果私有仓库需要认证,补充servers配置 --> <servers> <server> <id>excelfore.private</id> <username>你的仓库用户名</username> <password>你的仓库密码</password> </server> </servers> </settings>
配置完成后直接运行插件命令即可,Maven会自动从私有仓库查找构件。
方案2:清理本地仓库校验标记(快速解决单次问题)
直接删除对应版本目录下的来源校验和失败缓存文件:
rm ~/.m2/repository/com/excelfore/appshack-maven-plugin/4.2133-RC1/*.lastUpdated rm ~/.m2/repository/com/excelfore/appshack-maven-plugin/4.2133-RC1/_remote.repositories
删除后添加-o离线参数运行插件即可直接调用本地文件:
mvn -o com.excelfore:appshack-maven-plugin:4.2133-RC1:run-self-test
方案3:运行时临时指定插件仓库(无需修改配置文件)
运行插件命令时通过参数指定私有仓库地址:
mvn com.excelfore:appshack-maven-plugin:4.2133-RC1:run-self-test -DpluginRepositories=excelfore.private::::https://你的私有仓库地址
内容的提问来源于stack exchange,提问作者Pawel Veselov
相关产品推荐
相关产品推荐

