. Advertisement .
..3..
. Advertisement .
..4..
The error: “compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
What is “compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag”?
You might get the following error when you begin spring-boot.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag: --release -> [Help 1]
What causes error?
The main cause of the above error comes from the version you are using. The error will occur if the java versions you are using do not match because you have to manage multiple projects. Or your current version of Java is old, not upgraded yet.
How to fix it?
We have summarized some solutions below to help you quickly fix the above error. Take a look and choose the method that is right for you.
Approach 1: Delete tag release in maven-compiler-plugin
- Access your pom.xml file first
- Then, look for configuration for maven-compiler-plugin
- Delete the <release>8</release> tag in your maven-compiler-plugin configuration
- Now, try running your project again
- Your problem must be fixed.
- Your POM.xml will be like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
Approach 2: Set compiler flags directly in the properties tag
In this way, instead of you using the <configuration> tag, set the compiler flags directly to the properties tag you are using, like below:
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- Use the release flag only if you are using Java 9+ -->
<!-- <maven.compiler.release>8</maven.compiler.release> -->
<!-- verbose is useful for debugging purposes -->
<maven.compiler.verbose>true</maven.compiler.verbose>
</properties>
Approach 3:
Information from maven-compiler-plugin says that only from version 1.9 and later, release flags are supported. So you can check the JDK version you are using to fix the error. For those who are using 1.8 or below, you need to comment/removed from POM.
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Leave a comment