简体   繁体   English

Intellij:如何将项目配置设置为java 1.8

[英]Intellij: How to set project configuration to java 1.8

I've got problem to build my project in Intellij because of theoretically wrong java version: 由于理论上错误的Java版本,我在Intellij中构建项目时遇到问题:

在此处输入图片说明

In reality my project settings are set correctly: 实际上,我的项目设置已正确设置:

在此处输入图片说明

Java 1.8 is also set as default JDK for my operating system. Java 1.8也被设置为操作系统的默认JDK。 Unfortunatelly, when I try o make my project, I get the following error: 不幸的是,当我尝试创建项目时,出现以下错误:

在此处输入图片说明

do you have any idea where should I change configuration in order to successfuly build my project? 您有什么想法要在哪里更改配置以成功构建项目?

Update After specyfying properties in pom.xml file: 在pom.xml文件中指定属性后更新

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

Project builds correcly. 项目正确构建。 Strangely, when I removed those properies (so went back to initial state) and tried to build the project again, everything worked fine. 奇怪的是,当我删除了这些属性(回到初始状态)并尝试重新构建项目时,一切工作正常。 Still, Intellij indcates,that my line causes an error as presented on the first picture. Intellij仍然指示,我的生产线仍引起错误,如第一张图片所示。 Does somebody know why? 有人知道为什么吗? In Editor -> Inspection section I've got selected option to respect project language level settings, so according to project configuration, it should be all right (but is not): 在“ 编辑器”->“检查”部分中,我选择了尊重项目语言级别设置的选项,因此根据项目配置,它应该没问题(但不是):

在此处输入图片说明

I found an answer! 我找到了答案! ActuallyI don't understand, why default version of java compiler is set to version 1.5 ... I hope you will find it also helpful 实际上我不明白,为什么将Java编译器的默认版本设置为1.5版...我希望您会发现它也对您有所帮助

在此处输入图片说明

If you do not specify maven.compiler.source and maven.compiler.target , then some default values are used, which are not 1.8. 如果未指定maven.compiler.sourcemaven.compiler.target ,那么将使用一些默认值,而不是1.8。 That' why compilation fails, as you have already witnessed. 正如您已经看到的那样,这就是编译失败的原因。

Once you add the right values in pom.xml, compilation succeeds, as you have also witnessed. 如您所见,一旦在pom.xml中添加了正确的值,编译就会成功。

Then, what happens is that IntelliJ IDEA caches these values somewhere, somehow. 然后,发生的事情是IntelliJ IDEA以某种方式将这些值缓存在某个位置。 (I thought that the IDEA project files are updated with the values taken from pom.xml, but judging by your experience, apparently not.) (我认为IDEA项目文件已使用从pom.xml中获取的值进行更新,但是根据您的经验来看,显然不是。)

Once the values have been cached by IDEA, you may remove them from the pom file, and things will continue to apparently work for a while. 一旦IDEA缓存了这些值,您就可以将它们从pom文件中删除,并且显然可以继续工作一段时间。 But things are in fact broken. 但是实际上事情已经破裂了。

So, if you re-import maven projects, or if you delete the IntelliJ IDEA indexes, (thus essentially purging the cached information,) then the problem will reappear. 因此,如果重新导入Maven项目,或者删除IntelliJ IDEA索引(从而从本质上清除了缓存的信息),则问题将再次出现。

So, the rule to remember is: if your project is making use of a pom.xml, then the pom.xml is the authoritative place to look for build, and the IntelliJ IDEA project properties dialog is not accurate anymore. 因此,要记住的规则是:如果您的项目正在使用pom.xml,则pom.xml是查找构建的权威位置,并且IntelliJ IDEA项目属性对话框不再准确。

I agree, it is not working very well, and it would be nice if the IntelliJ folks provided a solution that makes their project properties dialogs more consistent with pom.xml files and with whatever information they are caching. 我同意,它不能很好地工作,如果IntelliJ人员提供了一种解决方案,使他们的项目属性对话框与pom.xml文件以及所缓存的任何信息更加一致,那就太好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何自动化Intellij项目配置 - How to automate Intellij project configuration 如何使用IntelliJ中的Java 11目标Java 1.8进行编译 - How to compile with Java 11 target Java 1.8 in IntelliJ 如何将 Java 1.8 添加到 IntelliJ (OSX) - How do I add Java 1.8 to IntelliJ (OSX) IntelliJ的Project Structure中如何设置默认的Java版本? - How to set the default Java version in the Project Structure in IntelliJ? IntelliJ IDEA 2017.1.3给出错误-即使将Project SDK设置为Java 1.8 JDK也未定义Project SDK - IntelliJ IDEA 2017.1.3 giving error - Project SDK is not defined, even on setting Project SDK to Java 1.8 JDK 如何针对新项目问题调整Intellij配置? - how adjust Intellij configuration for new project problem? 如何使用gradle为Vert.x 3.2.x项目设置Intellij运行配置? - How to set up a Intellij run-configuration for a Vert.x 3.2.x project with gradle? 如何使用Intellij运行需要其他项目/模块的配置文件的Java类? - How do I run a java class, using Intellij, that needs configuration files from another project/module? 在 intellij 中获取“-source 1.7 中不支持方法引用”,但我的项目设置有 Java 1.8 - Getting “method references are not supported in -source 1.7” in intellij, but my project setting have Java 1.8 如何在 IntellIJ 中设置“编辑配置”? - How do you set the 'Edit Configuration' in IntellIJ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM