Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 maven.compiler.target each set to the value 1.8.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>8</release>
    </configuration>
</plugin>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading