5

I have just cloned a git repository for a maven project and then imported the project into STS as a maven project.

I set up the project and sub-modules as java 1.8 projects and then ran a maven update and then noticed that all the java 1.5 compiler settings seem to have been reapplied.

I cant figure out why eclipse is resetting this, even if I uncheck 'Enable project specific settings' it still reverts back to having this checked and for java 5 to be the default.

I read a post about setting the version in the maven-compiler-plugin configuration but this project does not currently have any configuration for that plugin in any of the pom files.

berimbolo
  • 3,319
  • 8
  • 43
  • 78

2 Answers2

5

In your pom.xml put this:

<project>
  ...
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  ...
</project>

The reason you'll have to do this is that "the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with". See Maven Compiler Plugin for further details.

When you run Maven update command from Eclipse without setting the explicit java version, the project will take the default Maven settings, that's why you end up with 1.5 Java version.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • Ok thanks, its strange that the original developer didnt include this in the readme notes. Is this specific to eclipse, as I can see intelliJ was used previously. – berimbolo Feb 05 '18 at 11:05
  • @berimbolo It's not specific to Eclipse, see this: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html –  Feb 05 '18 at 11:10
  • Yes it has worked actually so thanks, I am just unsure of why I need to be changing it! – berimbolo Feb 05 '18 at 11:14
  • Ah thanks, I guess my comment was poorly worded, I meant why I needed to add it to the pom file when other people have previously been contributing to the project and apparently using eclipse but didnt have to do it! – berimbolo Feb 05 '18 at 11:28
0

Eclipse Photon Release (2018) only seems to recognize up to Java 10. Using

<project>
  ...
  <properties>
    <jdk.version>11</jdk.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>
  ...
</project>

caused it to revert to 1.5. Replacing "11" with "10" was the best I could do to avoid compiler errors.