简体   繁体   中英

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:

在此处输入图片说明

In reality my project settings are set correctly:

在此处输入图片说明

Java 1.8 is also set as default JDK for my operating system. 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?

After specyfying properties in pom.xml file:

<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. 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

在此处输入图片说明

If you do not specify maven.compiler.source and maven.compiler.target , then some default values are used, which are not 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.

Then, what happens is that IntelliJ IDEA caches these values somewhere, somehow. (I thought that the IDEA project files are updated with the values taken from pom.xml, but judging by your experience, apparently not.)

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. 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM