Maven Compiler: Check syntax for Java version


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 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!

>Solution :

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:


Leave a ReplyCancel reply