Maven 构建在 Jenkins 上失败,但在本地机器上工作

Maven build fails on Jenkins, but works on local machine

我有一个全新安装的 Debian Wheezy 服务器 运行ning Jenkins 1.596(最新版本)从 official deb package.

安装

为了和 Jenkins 一起玩,我创建了一个新的 Maven-Project,它被 Git.

检出

当我 运行 Maven 构建这个项目时,在我安装了 Maven 版本 3.0.5 的本地机器上,通过执行 mvn3 package 构建成功,但是当我尝试构建Jenkins 服务器上的项目构建失败。

插件 maven-resources-plugin (maven-resources-plugin:2.6) 和 maven-compiler-plugin (maven-compiler-plugin:2.5.1) 在我的开发系统和 Jenkins 服务器上是相同的版本.

构建失败,因为 error: cannot find symbol 错误,在我的本地系统上构建项目时不会发生该错误。

这是 Jenkins 服务器在构建过程中生成的日志:

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/hidden/workspace
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url ssh://git@red.hiddencompany.com/srv/gitosis/repositories/hidden.git # timeout=10
Fetching upstream changes from ssh://git@red.hiddencompany.com/srv/gitosis/repositories/hidden.git
 > /usr/bin/git --version # timeout=10
using GIT_SSH to set credentials 
 > /usr/bin/git -c core.askpass=true fetch --tags --progress ssh://git@red.hiddencompany.com/srv/gitosis/repositories/hidden.git +refs/heads/*:refs/remotes/origin/*
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 0d5334724d01ec42ed23912f687eb412997eede8 (refs/remotes/origin/master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f 0d5334724d01ec42ed23912f687eb412997eede8
 > /usr/bin/git rev-list 0d5334724d01ec42ed23912f687eb412997eede8 # timeout=10
Parsing POMs
[workspace] $ /var/lib/jenkins/tools/hudson.model.JDK/JDK_7/bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven32-agent-1.6.jar:/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven/boot/plexus-classworlds-2.5.1.jar:/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven/conf/logging jenkins.maven3.agent.Maven32Main /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven /var/cache/jenkins/war/WEB-INF/lib/remoting-2.49.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven32-interceptor-1.6.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.6.jar 55526
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /var/lib/jenkins/jobs/hidden/workspace/pom.xml package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hidden 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hidden ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hidden ---
[INFO] Compiling 15 source files to /var/lib/jenkins/jobs/hidden/workspace/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /var/lib/jenkins/jobs/hidden/workspace/src/main/java/com/logicsale/hidden/aggregator/provider/hiddencompany/AmazonSellerRatingsProvider.java:[41,58] error: cannot find symbol
[INFO] 1 error
[INFO] -------------------------------------------------------------
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.745 s
[INFO] Finished at: 2015-01-14T09:32:55+01:00
[INFO] Final Memory: 16M/39M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project hidden: Compilation failure
[ERROR] /var/lib/jenkins/jobs/hidden/workspace/src/main/java/com/logicsale/hidden/aggregator/provider/hiddencompany/AmazonSellerRatingsProvider.java:[41,58] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR] 
[JENKINS] Archiving /var/lib/jenkins/jobs/hidden/workspace/pom.xml to com.logicsale.hidden/hidden/1.0-SNAPSHOT/hidden-1.0-SNAPSHOT.pom
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
channel stopped
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE

我尝试用 JDK7 和 JDK8 构建都失败了。

请查看 maven-compiler-plugin 中的 question and the accepted answer. Maybe it is a bug - 尝试将 maven-compiler-plugin 的版本更新到 3.1 或更高版本。