Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Compilation Failure but no errors found

Tags:

java

maven

I'm running a maven build in Java 8, using compatibility target Java 6. When I try to build with Maven in Eclipse (just this project mind you, all other projects in my workspace build just fine), I get a compilation failure from maven, but maven doesn't list any actual errors except a generic MojoFailureException. When I compile through eclipse itself (using ANT or straight Java, there are no compilation errors). Also when I build on a remote machine using Jenkins and the same source code, there also are no problems using maven. It's definitely a local problem and I can't quite figure it out.

[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

Relevant compiler plugin configuration:

<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>
like image 319
Tacitus86 Avatar asked Jul 18 '18 12:07

Tacitus86


1 Answers

I have the same problem with using JDK 11 to build a Maven project that targets Java 7. Try removing <fork>true</fork> (or set it to false instead), and that should fix it. (h/t to https://stackoverflow.com/a/39657410/278800)

I don't actually know what the root cause is, though. My guess is that some part of the java environment isn't being passed to the forked compile process, like e.g. JAVA_HOME. Or maybe it's because I'm using jenv to set my java version, and that doesn't work with the forked process.

like image 99
Steve K Avatar answered Oct 06 '22 02:10

Steve K