Maven 编译失败但未发现错误

Tac*_*s86 7 java maven

我正在 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
Run Code Online (Sandbox Code Playgroud)

相关编译器插件配置:

<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>
Run Code Online (Sandbox Code Playgroud)

Ste*_*e K 4

我在使用 JDK 11 构建面向 Java 7 的 Maven 项目时遇到了同样的问题。尝试删除<fork>true</fork>(或将其设置为false),这应该可以修复它。(h/t 至/sf/answers/2776018731/

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