jenkins 用 Maven 打包出现 找不到符号 问题的解决方法

来源:互联网 发布:在线音乐软件 编辑:程序博客网 时间:2024/06/06 09:15

1 发现问题

今天用 持续集成工具 jenkins 打包一个新项目,出现了很多错误:

...[ERROR] [ERROR] \ideaProjects\xxx\ProjectService.java:[201,73] 错误: 找不到符号[ERROR] [ERROR] -> [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/MojoFailureExceptionProcess finished with exit code 1

用 idea 中的 Maven 工具直接打包也是报这个错误,在 maven 命令行中加入compile -e -X 后,可以看到详细的出错日志:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.1:compile (default-compile) on project supervise: Compilation failure    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656)    at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)    ... 26 more[ERROR] [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

2 寻找原因

奇怪的是,如果事先在 idea 中用 tomcat 运行过后一次以后,就可以顺利编译了。但持续集成工具只能使用 maven 的 compiler 工具直接编译。

发现 maven-compiler-plugin 2.x 使用的是 javac 编译,而 maven-compiler-plugin 3.x 就改用 javax.tools.JavaCompiler(jdk 6 以上,我们用的是 jdk 7) 了,这么看,估计是 javac 的问题了。

3 解决

把 maven-compiler-plugin 改为 3.x 版本,编译成功!O(∩_∩)O ~

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-compiler-plugin</artifactId>    <!--<version>2.3.1</version>-->    <version>3.6.1</version>    <configuration>        <source>1.7</source>        <target>1.7</target>        <encoding>utf8</encoding>    </configuration></plugin>
0 0
原创粉丝点击