【问题标题】:Maven Compilation Failure but no errors foundMaven 编译失败但未发现错误
【发布时间】:2018-07-18 12:23:56
【问题描述】:

我正在 Java 8 中运行 Maven 构建,使用兼容性目标 Java 6。当我尝试在 Eclipse 中使用 Maven 构建时(请注意这个项目,我的工作区中的所有其他项目都构建得很好),我得到一个来自 maven 的编译失败,但 maven 没有列出除通用 MojoFailureException 之外的任何实际错误。当我通过 eclipse 本身编译时(使用 ANT 或直接 Java,没有编译错误)。此外,当我使用 Jenkins 和相同的源代码在远程机器上构建时,使用 maven 也没有问题。这绝对是本地问题,我无法弄清楚。

[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ 
DataAdapterFB1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 58 source files to C:\Users\user\Desktop\GitRepo\FB1DataAdapter\code\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.460 s
[INFO] Finished at: 2018-07-18T08:20:37-04:00
[INFO] Final Memory: 11M/489M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project DataAdapterFB1: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project DataAdapterFB1: 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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1165)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
[ERROR] 
[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

相关编译插件配置:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                    <executable>${JAVA_6_HOME}\bin\javac.exe</executable>
                    <compilerArguments>
                        <bootclasspath>${JAVA_6_HOME}\jre\lib\rt.jar</bootclasspath>
                    </compilerArguments>
                    <fork>true</fork>
                </configuration>
            </plugin>

【问题讨论】:

  • 您好,您是否尝试使用调试模式? mvn -X ...
  • 当然可以。但是它太大了,无法添加到帖子中。不过,我没有在结果中看到任何相关内容。
  • 您可以尝试从编译器插件配置中删除除sourcetarget 之外的所有内容吗?
  • 您是否在源代码中使用过 lambdas 或函数式接口或菱形运算符?
  • 在OS环境中设置JAVA_HOME而不是pom.xm,然后重试。

标签: java maven


【解决方案1】:

我在使用 JDK 11 构建以 Java 7 为目标的 Maven 项目时遇到了同样的问题。尝试删除 &lt;fork&gt;true&lt;/fork&gt;(或将其设置为 false),这应该可以解决问题。 (h/t to https://stackoverflow.com/a/39657410/278800)

不过,我实际上并不知道根本原因是什么。我的猜测是 java 环境的某些部分没有被传递给分叉的编译过程,例如JAVA_HOME。或者可能是因为我使用jenv 设置我的java 版本,而这不适用于分叉进程。

【讨论】:

  • 虽然这并没有使我的项目编译,但它揭示了潜在的错误:-)
猜你喜欢
  • 1970-01-01
  • 2011-03-09
  • 1970-01-01
  • 2017-12-02
  • 1970-01-01
  • 2018-11-22
  • 2021-10-07
相关资源
最近更新 更多