Search code examples
javamaven

maven-compiler-plugin and JVM version


Is it possible to create a JAR using the maven-compiler-plugin, setting a specific compiler version?


Solution

  • You can not really set the compiler version (as maven uses what's installed), but you can configure source and target level on the maven-compiler-plugin:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin> 
    

    Edit: As khmarbaise points out in the comments, you can specify a different compiler, if you must, but you will have to set fork to true and specify the path to the executable, which, in the usual case, is not the kind of complication that you'd want. But he's right nonetheless, it's actually possible, and apparently has been since version 2.0 of the maven compiler plugin.