[英]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):
在“ 编辑器”->“检查”部分中,我选择了尊重项目语言级别设置的选项,因此根据项目配置,它应该没问题(但不是):
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.source
和maven.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.