0%

Jenkins打包不能发现本地仓库包

jenkins里新建了一个maven风格的项目,打包过程中找不到ojdbc的包,然后手动下载,加载到本地仓库中了,jenkins依然提示找不到这个包。

1
2
3
[ERROR] Failed to execute goal on project atmosphere: Could not resolve dependencies for project com.ths:atmosphere:war:0.0.1-SNAPSHOT: Failure to find com.oracle:ojdbc14:jar:10.2.0.4.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project atmosphere: Could not resolve dependencies for project com.ths:atmosphere:war:0.0.1-SNAPSHOT: Failure to find com.oracle:ojdbc14:jar:10.2.0.4.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:221)

手动加载jar包到本地仓库

1
/usr/local/apache-maven-3.3.9/bin/mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=/usr/local/src/ojdbc14-10.2.0.4.0.jar

手动maven编译打包

在工作目录下尝试手动编译打包,可以成功

1
/usr/local/apache-maven-3.3.9/bin/mvn compile install package

然后我茫然了,同一台机器,同一个版本的jdk,同一个版本的mvn,同一份代码;本地maven编译打包可以成功,通过jenkins调用maven打包就找不到ojdbc的包,失败了;容我喝杯白开水压压惊!
我仔细排查了jenkins里边的配置,maven的全局配置使用的是默认的;maven版本和本地是一样的3.3.9;maven的仓库是默认地址~/.m2/repository;终于发现问题的所在了,
原因就是maven的仓库是不一样的;本地执行maven编译打包使用的是root用户,仓库地址为/root/.m2/repository; jenkins程序是以jenkins用户启动起来的,默认的仓库地址为/var/lib/jenkins/.m2/repository/;
我之前手动导入jar只导入到root用户下的仓库中了;

解决方法

直接拷贝jar包到

1
cp /root/.m2/repository/com/oracle/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.jar /var/lib/jenkins/.m2/repository/com/oracle/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.jar

修改本地maven仓库的地址

1
2
3
vim $MAVEN_HOME/conf/settings.xml

<localRepository>/path/.m2/repository</localRepository>

扩展阅读

maven仓库的优先级别:本地仓库 >profile > pom中的repository > mirror
http://toozhao.com/2012/07/13/compare-priority-of-maven-repository/