Maven Build Failure – Compiler Plugin

We Are Going To Discuss About Maven Build Failure – Compiler Plugin. So lets Start this Java Article.

Maven Build Failure – Compiler Plugin

  1. Maven Build Failure – Compiler Plugin

    You need Java 11 to build the project. I was able to build it locally using JDK 11. I used maven wrapper. You can try using the following command.
    ./mvnw clean install
    Please try again after switching to JDK 11 and make sure you checkout the master branch.

  2. Maven Build Failure – Compiler Plugin

    You need Java 11 to build the project. I was able to build it locally using JDK 11. I used maven wrapper. You can try using the following command.
    ./mvnw clean install
    Please try again after switching to JDK 11 and make sure you checkout the master branch.

Solution 1

Changing the Lombok version worked for me. I updated my Lombok version to the latest.

Original Author Of This Content

Solution 2

Steps to resolve :

  1. Do mvn –version :
    Maven home: /Applications/apache-maven-3.8.1
    Java version: 1.16.0_291, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre
    Default locale: en_IN, platform encoding: UTF-8
    OS name: “mac os x”, version: “10.15.7”, arch: “x86_64”, family: “mac”

  2. If your Java version if different from what is project expecting like in my case 1.8 then change setting in environment variables:

nano ~/.zshenv -> append “-v 1.8” mention the version name.

here .zshenv file :


export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

export M2_HOME=/usr/local/Cellar/maven/3.8.1

export PATH=$PATH:$M2_HOME/bin


Do source ~/.zshenv

Now check again :
mvn –version :
Maven home: /Applications/apache-maven-3.8.1
Java version: 1.8.0_291, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: “mac os x”, version: “10.15.7”, arch: “x86_64”, family: “mac”

You will see version is changed to 1.8

Now build the project.

Original Author Of This Content

Solution 3

You need Java 11 to build the project. I was able to build it locally using JDK 11. I used maven wrapper. You can try using the following command.

./mvnw clean install

Please try again after switching to JDK 11 and make sure you checkout the master branch.

Original Author Of This Content

Solution 4

I faced the same problem. In my case mvn was using java version 17. The desired version for the project was java 8. Setting up the plugin configuration in the following manner did not help.

          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.8.1</version>
              <configuration>
                 <source>1.8</source>
                  <target>1.8</target>
              </configuration>
          </plugin>

It apparently only tells mvn current compiler (in my case java 17) to accommodate source as 1.8 and target as 1.8. The javac which is actually used by mvn for compilation of the project is still java 17. This arrangement, in my particular case, was not working and I was getting the error in question.
I had to instruct maven to use javac belonging to java 8 installation. This was achieved by setting an env variable JAVA_1_8_HOME pointing to java home as revealed by the versions installed on my mac system. The desired version /Library/Java/JavaVirtualMachines/openjdk-8.jdk/Contents/Home, found by running this command /usr/libexec/java_home -V was set in the JAVA_1_8_HOME environment variable.
The following configuration properties are required to be set for maven-compiler-plugin.

              <configuration>
                  <verbose>true</verbose>
                  <fork>true</fork>
                  <executable>${env.JAVA_1_8_HOME}/bin/javac</executable>
                  <compilerVersion>1.8</compilerVersion>
              </configuration>

Original Author Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment