How to change compiler compliance level to 1.8 in eclipse

Maven and Eclipse have always had a rocky relationship, and a common pain point between the two is how to force Maven JDK 1.8 support in new Eclipse projects. Without jumping through a few configuration hoops, the antiquated Java 1.5 version persistently remains the default and to fix this you must add a reference to the Maven compiler plugin in the POM.

The Eclipse IDE became popular before the Maven revolution really took hold, so the IDE’s support for the build tool always felt like an afterthought. Even with recent releases like Eclipse Photon, tasks such as importing Maven projects or creating anything more than a basic Maven project is less than graceful.

Maven JDK 1.8 use in Eclipse

A reminder of this rocky relationship is the fact that Eclipse and Maven have a habit of forcing Java 5 compliance on new applications, even if JDK 1.8 is the only JVM installed on the development machine. The Java 1.5 compliance issue means Lambda expressions, stream access or newer language features besides generics won’t compile.

Some developers try and change the Java compiler setting within Eclipse from Java 1.5 to Java 1.8, but that only works temporarily. As soon as a new Maven build takes place, the JDK version reverts back to 1.5. The only way to make this a permanent change is to edit the Maven compiler plugin POM entry and force Eclipse and Maven to use Java 1.8.

How to change compiler compliance level to 1.8 in eclipse

Eclipse Maven JDK 1.8 compliance and support

Of course, there is a fairly simple answer to this problem. That’s why everyone loves Maven. The build tool always has a simple resolution on offer. To force Eclipse and the Maven compiler plugin  to have JDK 1.8 compliance on your new projects, simply add the following to your POM file:

<!-- Force Eclipse and Maven to use a Java 8 JDK compiler-->
<properties>
  <maven.compiler.target>1.8</maven.compiler.target>
  <maven.compiler.source>1.8</maven.compiler.source>
</properties>

Maven Java 1.8 plugin support

An alternate, albeit slightly more verbose approach to tell Eclipse and Maven to use Java 8 or newer compilers is to configure the Apache Maven plugin:

<!-- Build plugin to force Maven JDK 1.8 compliance -->
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
  </plugins>
</build>

Maven compiler plugin and Java 11

Note that since the 3.8.0 version of the Maven compiler plugin, you can actually specify the release version of Java rather than source and target:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
  <configuration>
    <release>11</release>
  </configuration>
</plugin>

Eclipse Java 1.8 compiler setting

Once the maven-compiler-plugin change is made to the POM, you can open up Eclipse’s Java compiler properties page and notice that JDK compliance has changed from JDK 1.5 to 1.8.

How to change compiler compliance level to 1.8 in eclipse

When the POM updates to Maven JDK 1.8 support, the Eclipse Java compiler page reflects the change.

It’s a tedious problem but it’s also one that is easily fixed by a quick edit to the Maven compiler plugin. Furthermore, you only need to edit the POM file once on a project to force Eclipse and Maven to use Java 8 or Java 11. It’s really not all that big an inconvenience to overcome.

How do I change my compliance level in Eclipse?

Path to go to Project Properties: Right click on Project –> click Properties –> Java Compiler –> Change Compiler compliance level to required level. For example, Java 1.6 version for this case to work. Select 1.6 version from drop-down list and click Apply. ... .
Useful Eclipse IDE shortcuts :.

How do I change the default compiler compliance level in Eclipse?

How to change Java compiler version for Eclipse project.
Install JRE/JDK that supports the Java version you want to use..
Add that JRE/JDK to Eclipse's list of installed JREs..
Update Java Build Path for the project, pointing to the new JRE/JDK..
Change Java compiler compliance level..

How do I change the compiler version in Eclipse?

To change the compiler version in eclipse you need to go to Windows > Preferences > Java > Compiler. There you will see Compiler Compilation Level where in drop-down you will see all compiler version available in system.

Where is compiler compliance level in Eclipse?

The Compiler compliance level is set by default at 1.8 at Windows / Preferences / Java / Compiler. I set it to 15, and then restart Eclipse.