News Stay informed about the latest enterprise technology news and product updates.

How to force Maven JDK 1.8 support through the POM file

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.

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 POM and force Eclipse and Maven to use Java 1.8.

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 Maven 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-->

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 -->
      <!- Force Maven to use Java 1.8 -->

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.

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. Furthermore, you only need to edit the POM file once on a project to force Eclipse and Maven to use Java 8. It’s really not all that big an inconvenience to overcome.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.