Home > Back-end >  Maven Compiler: Check syntax for Java version
Maven Compiler: Check syntax for Java version

Time:12-23

I have a question of understanding:

Suppose I have Java code and use Java 11 syntax there (e.g. isBlank() from String class).

For compiling I use the maven-compiler-plugin (3.8.1) with the properties maven.compiler.source and maven.compiler.target each set to the value 1.8.

If I compile mvn clean (java -version = openjdk version "11.0.3" 2019-04-16) it works fine.

Is the java version I give to the maven-compiler-plugin only informative? How can I make sure that I get an artifact that really works under Java 8. Do I need to have JDK 8 installed (i.e. java -version = 1.8)?

Thanks a lot!

CodePudding user response:

maven.compiler.source controls what syntax you can or can't use, but it doesn't limit what methods from the JDK the code can be compiled against. For that, you can use the release property. E.g:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>8</release>
    </configuration>
</plugin>
  • Related