spring boot 引用nexus中添加的第三方jar包时,jenkins打包失败的临时处理方案
说明
看标题很绕,那是因为我目前也不知道怎么处理,但是误打误撞找到了一个临时解决方案,为了防止以后复现此类问题无法解决,这里简单记录一下。
背景
springboot开发的项目、本地使用nexus搭建了maven库,使用gitlab做代码管理,同时配合jenkins进行自动部署。
整体流程就是提交代码到gitlab后,触发jenkins进行编译并部署到docker容器。开发过程中使用了一个第三方的jar包,手动上传到了nexus库中。
问题
清理了jenkins中的.m2缓存的包后,再次在jenkins中构建会提示如下错误:
Downloaded from maven-releases: http://我的nexusip/nexus/repository/maven-releases/e-iceblue/spire.presentation.free/3.9.0/spire.presentation.free-3.9.0.jar (37 MB at 64 MB/s)
[INFO]
...
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal on project data-maintain: Could not resolve dependencies for project 我的项目:jar:0.0.1-SNAPSHOT: Could not find artifact e-iceblue:spire.presentation.free:jar:3.9.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
[ERROR]
这里的spire.presentation.free-3.9.0.jar便是我使用的第三方jar包,很明显前面已经从我的nexus库中下载了,但是后面又去repo.maven.apache.org
中去查找没找的报错了。
解决方案
这个问题困扰了我好久,至今也没找到方案,不过阴差阳错间,找到了个临时方法。过程如下:
- pom文件中原本是这样的
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<repositories>
<repository>
<id>central</id>
<url>http://我的nexus地址/nexus/repository/maven-releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://我的nexus地址/nexus/repository/maven-releases</url>
</pluginRepository>
</pluginRepositories>
<modelVersion>4.0.0</modelVersion>
...
- 提交,并自动部署。会报上述错误。
- 将pom修改为:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<repositories>
<repository>
<id>com.e-iceblue</id>
<url>http://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<modelVersion>4.0.0</modelVersion>
...
- 提交,并触发自动部署。仍会报错。
- 修改pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- 删除了这些配置-->
<modelVersion>4.0.0</modelVersion>
- 提交,并jenkins进行构建。
- 竟然好了。
总结
先这样吧,后面找到了具体原因,在更新。