一、问题描述
如图:设置了通过idea设置了jdk的版本之后,运行 maven build,或者过一段时间之后,项目的编译 jdk 版本会回到 1.5 版本,再次修改还是回到1.5版本。

二、解决方式
This error means that you must not modify the project structure and build configuration like project dependencies, compiler settings, sources/resources directories etc using IDE UI dialogs. Instead, you must do corresponding changes in the Maven pom.xml file.
Because otherwise you will loose all such changes made in IDE UI after the project fill be Reloaded by the IDE from the maven build files (pom.xml).
1. 简单地说
Maven使用的默认Java编译器版本是Java 1.5。为了使Maven使用Java编译器的较新版本编译Java代码,需要在项目的POM文件(pom.xml)中显式指定Java编译器。
2. pom配置
在项目的父pom下添加插件:
<!--通过maven设置jdk的版本 防止idea设置jdk版本之后-->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
参考
https://blog.youkuaiyun.com/tgvincent/article/details/118089774
文章主要讲述了在IDEA中遇到的问题,即设置的JDK版本在执行Mavenbuild后会自动回滚到1.5。解决方案是在项目的pom.xml中添加maven-compiler-plugin插件配置,明确指定source和target为1.8,以确保Maven使用正确的Java版本进行编译。
1687

被折叠的 条评论
为什么被折叠?



