IntelliJ IDEA 源值1.5已过时,将在未来所有版本中删除

由于IDEA默认将项目源代码和目标代码版本设为JDK1.5,这已成为过时设置。文章提供了通过修改Maven Settings.xml文件来一劳永逸解决此问题的方法,避免在每个新工程中重复设置。通过在Settings.xml中添加特定内容,可以更新源值设置,同时分享了个人的Settings.xml配置示例,包含网络优化仓库的设置。

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

原因

IDEA默认把项目的源代码版本设置为jdk1.5,目标代码设置为jdk1.5

解决方案

你可能会搜索到很多的解决方案,比如下面这个比较优秀的一篇
https://blog.youkuaiyun.com/gdsgdh308227363/article/details/82251655
这些都是在IDEA里面进行一系列复杂的设置,而且每次弄一个新的工程如果你有强迫症不想看到这个提示的话都得为每个工程设置一遍,那么有没有什么一劳永逸的方法呢?答案是有的。
修改Maven的Settings.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>

什么?不知道Setting.xml文件在哪里?那赶快去百度一下maven .m2这个东西
在这里我就不再赘述。下面顺便带大家展示一下我的Settings.xml文件的相关配置
尤其是网络优化的配置哈哈。
网络优化仓库是用nexus repository弄的,有兴趣的可以去了解一下
话不多说上代码

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <!-- the path to the local repository - defaults to ~/.m2/repository
   -->
    <!-- <localRepository>/path/to/local/repo</localRepository>
    -->
    <mirrors>
        <mirror> <!--Send all requests to the public group -->
            <id>maven</id>
            <mirrorOf>*</mirrorOf>
            <url>http://maven.qingguatang.com/nexus/content/groups/open/</url>
        </mirror>
    </mirrors>
    <activeProfiles>
        <!--make the profile active all the time -->
        <activeProfile>maven</activeProfile>
    </activeProfiles>
    <profiles>
        <profile>
            <id>maven</id>
            <!--Override the repository (and pluginRepository) "central" from the Maven Super POM
                to activate snapshots for both! -->
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://maven.qingguatang.com/nexus/content/groups/open/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>http://maven.qingguatang.com/nexus/content/groups/open/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <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>
    </profiles>

    <pluginGroups>
        <pluginGroup>org.sonatype.plugins</pluginGroup>
    </pluginGroups>
    <servers>
        <server>
            <id>maven</id>
            <username>qingguatang</username>
            <password>qingguatang</password>
        </server>
    </servers>
</settings>

参考链接

https://www.jianshu.com/p/451271c4de11

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值