Maven compiler settings for Java 10 and above

Tom Joe :

I set compiler version in the maven pom.xml file like this:

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

Which version do I set for Java 10 and above ? Looks lije 10 or 1.10 won't work. Have the tags changed for Java 10 and above ?

public static void main(String[] args)
{
   try (var in = new Scanner(System.in))
   {
      System.out.print("Enter n: ");
      int n = in.nextInt();
      factorial(n);
   }
}

The compiler complains that it cannot resolve symbol var, despite setting version to 10 or 1.10.

MrsNickalo :

Here is a helpful link: http://tutorials.jenkov.com/maven/java-compiler.html

For Java 8 or earlier, use:

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

For Java 9 or later, use:

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=169695&siteId=1