Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>
Overview
Recently, after upgrading the version of IntelliJ idea, when compiling or packaging Maven project, a lot of errors often appear. The error prompts are basically syntax errors caused by incorrect JDK version. I didn’t pay much attention at the beginning. I thought that the default configuration had not been modified. So we changed java compiler in settings and language level in project
settings to our own version, such as JDK1.8, and the problem was solved temporarily. However, the same problem will happen occasionally in the next compilation or packaging (it was found later that the reason why it happened accidentally was due to the change of POM file)
Cause analysis
After investigation, it turns out that the root cause of this problem is that the JDK version is not configured in the pom.xml file of Maven. When the JDK version is not configured, java compiler and language level will automatically change back to the original default version 1.6 once the POM file changes
Solutions
The above problem can be solved by adding Maven compiler plugin plug-in to POM file and specifying the JDK version used by JDK. The configuration of Maven compiler plugin is effective for both java compiler and language level I now use JDK1.8, so I configure 1.8. In case of similar problems, the corresponding version number can be configured according to the specific JDK version<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Similar Posts:
- [Solved] Error:java: error: release version 5 not supported & Switch Unrecognized String
- Maven warnning: ‘build.plugins.plugin.version’ is missing [How to Solve]
- [Solved] Dynamic Web Module 3.0 requires Java 1.6 or newer
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1
- [Solved] Error:java: Compilation failed: internal java compiler error
- Error:java: javacTask: source release 8 requires target release 1.8
- Dynamic Web Module 3.1 requires Java 1.7 or newer
- How to Solve Maven Project Error: Cannot change version of project facet Dynamic web module to 3.0/3.1
- [Solved] SpringBoot Package Error: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-res
- How does IntelliJ idea use Maven Tomcat plug to run web projects