mvn clean install not working: Compilation failure

Viewed 39

I've been having this error since the first time I tried do run the command mvn clean install:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time:  41.009 s 
[INFO] Finished at: 2022-09-24T11:12:43-03:00 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project accounts: 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

picture: [1]: https://i.stack.imgur.com/FKUbm.png

My mvn version and my java version (I'll put them in text because the stackoverflow is not letting me add another picture):

$ mvn -version

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: C:\apache-maven\apache-maven-3.8.6 Java version: 17.0.4.1, vendor: Azul Systems, Inc., runtime: C:\Java\zulu17.36.17-ca-jdk17.0.4.1-win_x64\zulu17.36.17-ca-jdk17.0.4.1-win_x64 Default locale: pt_BR, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
$ java --version

openjdk 17.0.4.1 2022-08-12 LTS OpenJDK Runtime Environment Zulu17.36+17-CA (build 17.0.4.1+1-LTS) OpenJDK 64-Bit Server VM Zulu17.36+17-CA (build 17.0.4.1+1-LTS, mixed mode, sharing)

MY POM.XML FILE: https://github.com/vitoriaacarvalho/mvn-clean-install-error-description/blob/main/pom.xml

I've already tried so many things, and if you want any more details they are probably here: https://github.com/vitoriaacarvalho/mvn-clean-install-error-description I put together this repository to show all of the things I've tried to do, add more pictures, and even the pom.xml code!

1 Answers

I see that you have configured Maven to run on Java 17 on the IDE and even JAVA_HOME seems to point to the same. However your code needs to be run on JRE 1.8 ?

This I infer from that in your pom.xml you have :

  <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
                
                <configuration>
                    <fork>true</fork>
                    <executable>C:\Java\zulu17.36.17-ca-jdk17.0.4.1-win_x64\zulu17.36.17-ca-jdk17.0.4.1-win_x64</executable>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgument>-XDignore.symbol.file</compilerArgument>
                </configuration>
 </plugin>

In such case:

  1. Set your JAVA_HOME to Java 8 or JRE 1.8. If not set source and target to '17' (not 1.7 or 17.0).
  2. Your Maven needs to point towards the same, you can check that by mvn -v and java --version and echo %JAVA_HOME% commands
  3. If you have a .bat file on Windows for this Maven project, modify its set commands to point to right JAVA version.
  4. You may also want to add groupId, version etc tags to maven-compiler-plugin

Correct Way:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <compilerVersion>1.8</compilerVersion>      
        <fork>true</fork>
        <executable>D:\jdk1.8\bin\javac</executable>                
    </configuration>
</plugin>

My opinion is, this is caused because of JAVA versions mismatch.

Related