Java error Compilation failure Source option 5 is no longer supported

Java and Maven - Packaging Manager

This is a very common error for a beginner java for the first-time using maven. When you are compiling your Java application using Maven dependency management version 3.6. The following error will occur.

- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project java-test: Compilation failure: Compilation failure:

- Source option 5 is no longer supported. Use 6 or later.

- Target option 1.5 is no longer supported. Use 1.6 or later.


The solution is pretty simple, you just have to make sure you are using Java version 6 or higher. Then place this configuration in your pom xml.


    <properties>

        <maven.compiler.target>1.8</maven.compiler.target>

        <maven.compiler.source>1.8</maven.compiler.source>

    </properties>


Now you can execute this following maven command on your project application, using maven commands to package your project into a jar like the following.

mvwn clean package


This quick solution is working in my case, it demonstrates the possible ways of setting Maven build to specifying Java version target and Java version source.


If you have your project, you need to compile to a certain version of Java rather than what you are currently using. The javac from JDK can accept such parameters which are -source and -target. You configure that parameter on your maven pom.xml, then it will be applied during the compilation.


Example given if you want to use Java 11 language features then set the parameter -source 1.8, then if you want the compiled classes to be compatible with JVM 1.8 set the command -target 1.8. Both can be combined or if you leave it empty it will use the default java version set by the maven version you are using.


If you are working on a Spring Boot application then you can use a fancier type in the properties <java.version>. But specifying maven.compiler.source and maven.compiler.target properties should be the best option.


Popular posts from this blog

ERROR 1348 Column Password Is Not Updatable When Updating MySQL Root Password

Upload and Download Rest API using Spring Boot Reactive WebFlux

Spring Kafka - how to use ReplyingKafkaTemplate send and reply synchronously

How To Create Spring Boot Project Using Netbeans

What Is My Localhost IP, For Windows User?