【maven】【idea】通过maven指定JDK版本

文章主要讲述了在IDEA中遇到的问题,即设置的JDK版本在执行Mavenbuild后会自动回滚到1.5。解决方案是在项目的pom.xml中添加maven-compiler-plugin插件配置,明确指定source和target为1.8,以确保Maven使用正确的Java版本进行编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、问题描述

如图:设置了通过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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

roman_日积跬步-终至千里

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

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

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

打赏作者

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

抵扣说明:

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

余额充值