15

I have a project that is using Java 8.

Up to now in the pom we specified the source and target version as 1.8:

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

We want to utilize the "-release" Option of Java 9+ and added the following:

<maven.compiler.release>1.8</maven.compiler.release>

But now we get the following error:

Fatal error compiling: release version 1.8 not supported

We are using maven 3.5.3, the maven-compiler-plugin in version 3.8.0 and Java 10 to compile the project.

What is wrong here?

Naman
  • 27,789
  • 26
  • 218
  • 353
radlan
  • 2,393
  • 4
  • 33
  • 53
  • Why are you using different version for compiling? I mean Java 10 to compile project and Java 1.8 with maven? Use same versions – Adya Sep 20 '18 at 07:00
  • 2
    @Adya The project is compilable with Java 1.8 therefore this is the requirement in the pom. But of course it needs to be compilable with Java 10 as well. There is no reason to _only_ compile this project with Java 1.8 – radlan Sep 20 '18 at 07:02

2 Answers2

20

This should work

<maven.compiler.release>8</maven.compiler.release>

since the <release> attribute works with the major versions of releases only.

By, the way this is assuming that this is a parameter used in the actual compiler-plugin configuration somewhat like :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>${maven.compiler.release}</release>
    </configuration>
</plugin>
Naman
  • 27,789
  • 26
  • 218
  • 353
  • 4
    Yes, you are right! A bit inconsistent that `source` and `target` allow 1.8 as well as 8, but `release only` allows 8... – radlan Sep 20 '18 at 07:01
  • 2
    About your mentioning of the maven-compiler-plugin configuration: Yes, but indirectly. The above mentioned properties are only specified as properties. We did not mention those properties explicitly in the configuration block of the maven-compiler-plugin, since these properties are read automatically and do not need this explicit declaration as in your example. – radlan Sep 20 '18 at 07:04
  • @radlan Agreed, with the current the conventions practiced. It shall work when declared as properties as well. – Naman Sep 20 '18 at 07:12
  • 1
    @radlan This inconsistent is based on that JDK9+ has changes the version to 9.X whereas JKD8 and before where called `1.X`...furthermore the `--release ..` does only exist starting with JDK9+ but not before... – khmarbaise Sep 20 '18 at 07:22
  • @khmarbaise Is there any other documentation around the `release` attribute than the example usage here https://maven.apache.org/plugins/maven-compiler-plugin/examples/module-info.html ? Was wondering that would be helpful for people to understand when and why the attribute was introduced to the compiler plugin. – Naman Sep 20 '18 at 07:51
  • The official documentation of the javac tool, https://docs.oracle.com/javase/10/tools/javac.htm#JSWOR627 – Robert Scholte Sep 20 '18 at 16:46
  • @RobertScholte well actually, I was looking for a reference in the compiler plugin docs. – Naman Sep 20 '18 at 16:58
  • 1
    I'd prefer to point to the specifications over copying it. Specs should stay up to date, all content based on it probably not. But we can accept any PR :) – Robert Scholte Sep 20 '18 at 17:09
1

In my case I had to change release, source and target.

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.release>8</maven.compiler.release>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
  </properties>
Junior Vieira
  • 553
  • 5
  • 5