Maven: Setting Compiler Version

I recently started a new JavaFX project. I decided to use Maven because the tool is great for building Java projects in a standard way that conforms with best practices. Unfortunately, I’m not the most well versed in the tool. I’ve used it a few times, and “it just worked”.

This evening I got the following errors when attempting to compile my project:

Source option 5 is no longer supported. Use 7 or later.
Target option 5 is no longer supported. Use 7 or later.

I didn’t know what it meant, so I went to the Web. A search result later, I learned this had to do with the compiler. So I added the following directive to my pom.xml file.

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

I’m using openjdk-13, so I told Maven that my source code (compiler.source) would be written in Java 13; and that my output code (compiler.target) should run on the Java 13 JVM.

If we were to compile directly on the command line, we could use -source and -target flags reach the same end, but I believe Maven leverages a javax.tools.JavaCompiler object that enables invocation of the Java compiler from within programs. From what I can tell, it’s the Maven Compiler Plugin which uses such an object – hence, the maven.compiler.* directives.

Leave a Reply

Your email address will not be published. Required fields are marked *