16

I'm running Eclipse 2018-09 (4.9.0) on Windows 10. I'm using Open JDK 11 GA. I have a Maven project that was specified as using Java 8 source code.

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

That compiles fine using Maven 3.5.3 on the command line. That also compiles fine using Eclipse Eclipse 2018-09 (4.9.0).

I changed the compile Java versions to Java 11:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>11</maven.compiler.source>
  <maven.compiler.target>11</maven.compiler.target>
</properties>

That still builds fine on the command line using Maven 3.5.3. But in Eclipse 2018-09, I get errors all over the place:

  • '<>' operator is not allowed for source level below 1.7
  • Constructor references are allowed only at source level 1.8 or above
  • Default methods are allowed only at source level 1.8 or above

You get the idea.

I've already used Alt+F5 to update my Maven project (and subprojects) in Eclipse. I've done a complete clean and rebuild.

Because this compiles fine with Maven on the command line, this has to be an Eclipse problem, doesn't it? Sure, Eclipse doesn't support all new Java 11 features, yet, but this code has no Java 11 specific features. What's wrong?

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • 1
    Do you have the Java 11 plugin https://marketplace.eclipse.org/content/java-11-support-eclipse-photon-49? – JuanMoreno Sep 27 '18 at 15:04
  • 1
    I haven't tried it yet, because I'm not using any Java 11 features. Isn't the Java 11 plugin to add support for Java 11 features? If it only has Java 8 features, why can't it simply compile the same source code that it compiled for Java 8? Why does it need a plugin to do that? – Garret Wilson Sep 27 '18 at 15:07
  • I don't know. I tried to add the Java 11 plugin as you mentioned, and now Eclipse goes into an endless build loop. I've opened another question https://stackoverflow.com/q/52540355/421049 . – Garret Wilson Sep 27 '18 at 15:24
  • 1
    I've filed Eclipse bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=539570 . It's probably better to discuss it there. – Garret Wilson Sep 27 '18 at 19:27

4 Answers4

5

It sounds like Eclipse is not picking up the versions from the pom.

I just tested your pom configuration and verified that it works, either by providing compiler source and target properties like in the question or the new release property as described in this answer, using the latest Java 11 Support for Eclipse 2018-09 plugin.

It is important that the the JDK 11 is correctly set up in the Eclipse preferences. Add the JDK 11 on the "Installed JRE" preference page and then match it with the JavaSE-11 on the "Execution Environment" preference page. Otherwise updating the Maven project will result in the default JDK being used, which is likely the issue that you are having.

kapex
  • 28,903
  • 6
  • 107
  • 121
  • @GarretWilson I managed to reproduce the issue and updated my answer – kapex Sep 28 '18 at 14:36
  • 2
    But I already added OpenJDK 11 as the default JRE in Eclipse (which I did in https://stackoverflow.com/q/52520472/421049 ). There seem to be all sorts of version detection problems with Eclipse and Java 11. Did you see all the developer comments on my bug report https://bugs.eclipse.org/bugs/show_bug.cgi?id=539570 ? – Garret Wilson Sep 28 '18 at 23:59
  • @GarretWilson I understood those comments in the bug report as that it should generally work. And it does for me with a fresh Eclipse installation. So if Java 11 is configured correctly (Eclipse Java 11 support plugin installed + JDK 11 is set up), you should be able to change the Java version manually (or create a new Java 11 Project) and it should compile without those errors. Can you test that? – kapex Sep 29 '18 at 11:32
5

Update: Java 11 is fully integrated in Eclipse since Version 4.10 (released 2018-12-19), so one do not need to install this plugin anymore.


For some reason you need to install an additional Eclipse Plugin "Java 11 Support for Eclipse 2018-09 (4.9)" (even in Eclipse Photon 4.9)

It seams that the plugin is not available in Eclipse Marketplace anymore. I someone find its install url, please add it here:

Works for Eclipse - STS 4.0.1 (based on Eclipse 4.9) , Maven 3.6.0, with this Maven Compiler Plugin Configuration

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>                
        </plugin>
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • the link is broken, and I can find such a plugin only for java 12 – Árpád Magosányi Apr 09 '19 at 11:52
  • @Árpád Magosányi: you are right, the link is broken and I am not able to find this plugin too. -- sorry (btw: the current STS 4.2.0 based on Eclipse 4.11 does not need this plugin) – Ralph Apr 10 '19 at 09:56
  • The update site for the plugin for 2018-09 is here: http://download.eclipse.org/eclipse/updates/4.9-P-builds/P20180926-0920/ – atom88 Jun 28 '19 at 20:35
0

This problem is fixed in Eclipse 2018-12. Upgrading to that version will resolve your issue.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
0

No need to add any plugin.

You only need to upgrade eclipse such that it can handle jdk 11 compiler like mentioned in the attachment.

You don't need to upgrade eclipse in case you have the option to set the jdk 11 compiler.

**Note: Go to the Java Compiler post selecting the project properties and then Click on Configure Workspace settings to mention JDK 11.

JDK 11 Compiler Setting

chetan mahajan
  • 723
  • 7
  • 9