I use IntelliJ IDEA as my development environment, and Maven for dependency management. I frequently build my project structure (directories, poms, etc) outside of IDEA and then import the project into IDEA using Import project from external model. This works great, except that in my poms I specify that the maven-compiler-plugin should use JDK 1.6, and when I import, IDEA informs me that the Language Level Changed and that Language level changes will take effect on project reload, and then prompts to reload the project. This is annoying because I always use the same JDK version.

我如何改变IntelliJ IDEA使用的默认JDK,以便我不必每次导入新项目时都重新加载我的项目?


当前回答

我使用的是IntelliJ IDEA 14.0.3,我也有同样的问题。选择菜单文件\其他设置\默认项目结构…



选择项目选项卡,部分项目语言级别,从下拉列表中选择级别,此设置为所有新项目的默认设置。

其他回答

上面的回答非常有用,但在所有设置之后,项目运行的版本是错误的。最后,我注意到它也可以在Dependencies窗口中配置。 2018.1.3文件->项目结构->模块->来源和依赖项。

我正在使用IntelliJ 2020.3.1和文件>其他设置…菜单选项消失。我以通常的方式进入设置,搜索“jdk”。在构建,执行,部署>构建工具> Maven >导入下,我找到了将解决我的具体问题的设置:

用于导入器的JDK。

另一个值得检查的地方:如果您使用Maven编译器插件,请在项目的pom.xml中查看源/目标配置,并确保它是所需的Java版本。我发现我有1.7分;我将其更改为1.8,然后在IntelliJ中正确编译所有内容。

<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>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
</plugins>
</build>

在我的linux机器上,我使用这样的脚本:

export IDEA_JDK=/opt/jdk14
/idea-IC/bin/idea.sh

对于最新版本的intellij,为新项目设置默认jdk/sdk请转到

配置->结构的新项目->项目设置->项目SDK