Tinki
Tinki

Reputation: 1526

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:

enter image description here

In reality my project settings are set correctly:

enter image description here

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:

enter image description here

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:

<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):

enter image description here

Upvotes: 2

Views: 4854

Answers (2)

Tinki
Tinki

Reputation: 1526

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

enter image description here

Upvotes: 3

Mike Nakis
Mike Nakis

Reputation: 61984

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.

Upvotes: 1

Related Questions