Coffee Talk: Java, News, Stories and Opinions

Apr 22 2019   2:58PM GMT

How to force Maven JDK 1.8 support through the POM file

cameronmcnz Cameron McKenzie Profile: cameronmcnz


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.

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

Eclipse Maven Java 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.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: