解决Intellij IDEA maven 自动设置JDK为JDK1.5

在idea中创建maven项目,每次更新或重新载入maven项目后,都会重新变成JDK1.5,就算手动设置maven项目或者模块JDK1.8,刷新后还是会变为JDK1.5。这是由于创建项目时没有指定jdk版本,而maven的默认jdk版本为1.5导致的。

解决方法:

1.在当前maven项目pom文件中指定编译的jdk版本(项目指定)

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

2.使用 maven-compiler-plugin 插件指定当前项目编译的jdk版本

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

3.针对于SpringBoot项目,只需指定java.version即可

<properties>
	<java.version>1.8</java.version>
</properties>

4. 设置 maven 全局jdk版本(针对idea配置的本地maven)

在本地maven目录下conf文件夹内的setting.xml配置文件中加入以下配置(全局配置,一劳永逸)

<profile> 
	<id>jdk-1.8</id>
	<activation>
		<activeByDefault>true</activeByDefault>
		<jdk>1.8</jdk>
	</activation>
	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
	</properties>
</profile>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

angulaer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值