在 Jenkins 中,使用 maven 打包报 package xxx does not exist 问题的解决方法

1 发现问题

今天打算使用 Jenkins 给一些旧项目打包,编译时报以下错误:

...
[ERROR] /var/lib/jenkins/workspace/fsti-pipe/src/main/java/com/fsti/oss/service/sys/PagerService.java:[6,52] package org.springframework.beans.factory.annotation does not exist
...

看日志,直接原因是 spring 的 某些 jar 包不存在!

2 寻找原因

在本地开发环境下,用 idea 的 maven 搭建了与 Jenkins 相同的 maven 环境(启用了新的本地仓库、使用相同版本的 maven-compiler-plugin),可以正常编译!这说明一定是其他原因造成的。

在 Jenkins 中,打开对应项目的【配置】链接,然后点击【构建】页签,在 Goals 中为 Maven 加入 -e -X 参数,并保存。

这样会让 Maven 在构建时打印出更详细的日志。

现在项目再重新构建一次,再看看输出的日志。

配置的仓库已经被使用咯,说明仓库的配置没有问题:

[DEBUG] Using mirror nexus (http://xxx:8383/nexus/content/groups/public/) for snapshots (http://xxx:8081/nexus/content/repositories/snapshots).
...
[DEBUG] Repositories (dependencies): [nexus-all (http://xxx:8081/nexus/content/groups/public, default, releases+snapshots), nexus (http://xxx:8383/nexus/content/groups/public/, default, releases+snapshots)]
...

jdk 打包时引用的依赖包路径有问题,居然会是 /xxx/D:\Program Files\apache-maven\repo... 格式的,这很明显不是 linux 的正确路径嘛:

[DEBUG] -d /var/lib/jenkins/workspace/fsti-pipe/target/classes -classpath /var/lib/jenkins/workspace/fsti-pipe/target/classes:/var/lib/jenkins/workspace/fsti-pipe/D:\Program Files\apache-maven\repo/com/fsti/agile/fsti-agile/1.1.1/fsti-agile-1.1.1.jar:
...

至此可以确定是 maven 的 setting.xml 里面的 localRepository 配置路径的不对,造成了上述问题。一看果然是这样。

3 解决问题

把 maven 的 setting.xml 的 localRepository 改为正确的配置路径即可!记住这个路径在 linux 中必须有读写权限的哦 O(∩_∩)O~

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值