公司在开发过程中经常需要把代码发布到内网服务器,所以用Jenkins做一键构建。然后在构建我们的一个Maven项目时遇到了一个错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project lano-cloud-zjxxw: Compilation failure -> [Help 1]
[ERROR] 
[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

不明白什么意思,就各种搜索,网上有一些这类的错误贴,研究了下最后把问题解决了,但是说的太笼统,我这里自己做一下记录,当做是学习笔记吧。

这个错误的意思是Maven在构建时,查找JDK环境遇到了问题。我原来pom.xml中关于maven-compiler-plugin是这样配置的:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

这里需要给出JDK的具体地址:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <fork>true</fork>
        <executable>/usr/local/jdk8/bin/javac</executable>
    </configuration>
</plugin>

保存之后,在服务器本地和Jenkins上,都能构建成功。

Last modification:May 29th, 2020 at 03:31 pm