Java version keeps getting reset to 1.5 when I change something (libraries in Project Settings?)

Answered

Something is changing Java versions on me - from my selected 1.8 to 1.5. I need to fix this in two places

  1. Project Settings -> Modules -> Sources and set language level
  2. .idea/compiler.xml: change <module name="DroolsGameEngine" target="1.5" /> to 1.8

I think this is when I modify libraries via Project Settings. Whatever the cause, I would like to be able to change this default 1.5 to 1.8, but I don't know where to look to achieve this. Any pointers most welcome.

Thanks,

11
39 comments
Avatar
David Borris Fell

Wonderful! Yes, it's a maven project. Blended the example into my pom.xml and made a library change and no complaints about java version being wrong. Many thanks!

0

I have the same problem, but my pom is correctly configured. Here's what the effective pom shows:

 

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<target>1.8</target>
<source>1.8</source>
<compilerArgs>
<arg>-Xlint:all,-processing</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>

And, yet, everything resets to 1.5 every time I reimport projects.
0

Please submit a ticket to support with the sample project to reproduce attached.

0
Avatar
Permanently deleted user

I am having the exact same problem with a simple Gradle Java project.  I have to constantly reset the Target bytecode version from 1.5 to 1.8 in Settings > Build, Execution, Deployment > Compiler > Java Compiler whenever I add or change a file.  I also have to do the same thing in Project Structure > Modules.  I will submit a support ticket a well with my project.

1

Do you specify sourceCompatibility and targetCompatibility in your Gradle build file?

0
Avatar
Permanently deleted user

Specifying sourceCompatibility and targetCompatibility in build.gradle solves the problem for me.  Thanks.

0
Avatar
Permanently deleted user

Did anyone create an actual ticket? (I'll do so in a week if no response)  We've seen this all the time for years - to the point where we now have a script to rewrite the *.iml files back to the desired JDK level. Note this isn't about any specific JDK level. FYI our projects are mixed Java/Scala + Maven 3.3.3 and (obviously?!) we set source and target to 1.8

For anyone else's edification, you need to change the following in your iml files.

LANGUAGE_LEVEL="JDK_1_8"

P.S. the original Maven question posted is not answered by this thread

2

There is an open issue specific to Maven, please see https://youtrack.jetbrains.com/issue/IDEA-115977.

0

this is still happening 2 years since your post

everything in my project gets the 1.8 from a parent module 

there are NO references to 1.5 anywhere

yet IDEA keeps changing both the .iml and compiler.xml to 1.5

this is making your product almost useless

give me a flag to stop you from messing my configuration

0

We've fixed most of the issues related to the Maven language level configuration.

If it still affects your project, please file a new bug at https://youtrack.jetbrains.com/issues/IDEA and attach a sample project to reproduce it.

0

i finally got a cure for this

our parent uses maven-compiler-plugin

when i ALSO define these two properties the problem gets fixed (either the plugin or the properties should work independently)

maven.compiler.source & maven.compiler.target to 1.8

0

This isn't a bug I don't think.

 

Sort through the project and add these to any of the modules which keep reverting to 1.5

 

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
0

We have a parent pom that is in all the projects.  It defines the maven-compiler-plugin as shown above.  In some of our very complex systems with multiple pom's Intellij seems to lose the content of the parent pom.  Maven always works well and always uses 1.8.

I found that by adding maven.compiler.source & maven.compiler.target as properties to the SAME parent pom that Intellij can easily read these so that was our fix.

I left both the properties and the plugin in place and the problem did get resolved.  It is definitely a bug as only Intellij started switching to the default language level.  And our complex pom layouts work fine with other IDEs and with Maven directly.

I would recommend that the default language should be defined by the user.  We do set the language to 8 on the top configuration page but your system still chooses 5 as the default. If 8 were the default I would never have seen the bug as 8 would have been the override for 8.

Anyways, thanks for the response.

0

I believe it to be with filesystem i/o caching.

It seems as if intelliJ is very much out of sync sometimes - most notably between ssd/hdd jvm location&codebase location.

 

You could easily do by hand or write a script to search all dependencies of your project for a) does not match & b) does not-contain in file

Ctrl+Shift+R

            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
0

these are NOT changing by us. our projects are quite stable so there is no syncing of the poms with disk & memory.

i have gone and made compiler.xml to only contain 1.8, i have gone and made all .iml files to only contain 1_8 language level.  we set the jdk and the language level to 8.  yet sometimes when i am debugging and a build occurs first the compiler.xml changes many projects to 1.5 then tells me i cannot compile our code with java 5.

anyways, after adding maven.compiler.source & maven.compiler.target properties to the parent pom (which had the maven-compiler-plugin) this has stop happening

0

I can't say for sure it is presently fixed, but people on our company have had trouble with it last year. If the fix is pre-2018, it didn't fix it.

I believe I have mentioned the issue does seem to happen when the parent of the root pom of a project is an external dependency, so it shouldn't come as news to anyone following this issue. Specifying version in every project is not a fix, it is a contingency workaround IntelliJ not handling maven poms as it should, and an unacceptable one for us.

We do not have source and target specified by properties, but by plugin. Though IntelliJ _should_ respect plugin configuration, specifying those properties once in the external dependency, if it works, is acceptable, so I'll try that out.

On the speculative side, I've noticed that sometimes, when editing pom files and introducing an XML error -- which can easily happen in the middle of editing of a pom file with auto-reload on -- IntelliJ will act weird, neither complaining about the error, nor, obviously, loading the configuration. I do wonder if the issue might be triggered under these circumstances. 

 

0

It is really the fact of the matter that if intelliJ is not doing it automatically for you, you must specify the source and target properties to the desired language level.

Start intelliJ with the project, click file -> invalidate caches/restart & do both of them.
Once done, modify all of your poms in every project to add or modify the source/target properties, and then save all of them, synchronize the filesystem, & restart intelliJ.

0

Uh, no. Please, if you are going to advise doing things, stay away from things you do not understand. If you are placing source and target properties in every pom file, you are doing it wrong. That's not how it is supposed to work. You define it ONCE, on the parent pom for all the projects sharing those common properties, and inherit it everywhere else. Maven will read that parent pom, will download it if necessary, and use the properties as you defined them. IntelliJ will too, as long as it isn't broken.

0

I have stated above, and it seems we have had very similar behaviors (Dcsobral), that the answer that might help you as it definitely solved my similar issues is to use these two properties IN THE PARENT POM:

 <maven.compiler.source>1.8<maven.compiler.source>

 <maven.compiler.target>1.8<maven.compiler.target>

 

From my testing, it seems that Intellij can process these two properties and Intellij has a lot more problem with the maven-compiler-plugin on very complex systems.

 

0

I don't see this all the time usually, but it's been happening a bunch lately. I have the same (fairly standard) setup as Scott and Dcsobral: parent pom with compiler plugin configuration including source and target levels.

For me it only happens on one or two modules in my workspace. I have multiple related maven projects that I load in as module groups. They all share the same parent that has the compiler plugin configuration. When I import modules, they all come in at language level 5 despite the maven settings, but I can just override it in the project settings. For some of the modules, it doesn't seem to actually respect the override though. I've checked the IML file for the projects that are having problems but they say 1.8 like they should. I basically just turn all the knobs I can think of until it randomly starts working.

0
 

@David Harris

 

Change and or add the two lines below, to all pom packages that you NEED to be Java 8 (hence "need to be" - Dcsobral)

```

<maven.compiler.source>1.8<maven.compiler.source>

<maven.compiler.target>1.8<maven.compiler.target>

```

 

AS WELL AS, changing the java version specified in the .iml files that intelliJ creates for your modules.

The problem is that once you change the maven version, the very next time you restart or invalidate your caches in anyway, intelliJ will overwrite the pom files because the .iml file's java version of any given module does not match the pom for that given module.

 

And Yes, I know what I am talking about.

Read my name.

I am a beast.

1

Hell's bells, I have wasted tons of time on this BUG. None of the work arounds seem to work. I have the latest version of everything. I even created a little test project and that hit the dirt on the version 5 bug. 

I'll be happy to work with anybody at JetBrains to help fix this really nasty bugf.

 

Thx. Mark

0

Please submit a ticket at https://intellij-support.jetbrains.com/hc/requests/new and attach a sample project.

0

I'm here for my 3rd go-round with this. Each time I stumble my way forward until miraculously something works, but I'm never quite sure which combination of actions does the trick. Maybe I held my mouth just right when I clicked build?

I see the comments have multiplied since my last visit to this page, and debate as to whether it is a bug or not has emerged. It shouldn't matter whether this is a bug or a "feature". The fact is, users are having a negative experience around this. If you care about that, do something. You guys have a great product, but this particular issue frustrates me to no end. I would hate to be forced to move to an inferior product over such a seemingly minor but nonetheless intractable problem.

Please just put all the controls for java version & language level in one place. This wouldn't be nearly such a problem if controls weren't scattered across multiple places in the settings, the POM, the .iml files, etc. Make it clear where the settings are coming from, and give a *single* place to control that. If the POM settings are going to be ignored (as they are, for me, though I can't figure out why) make that clear in the settings, and explain why & how to change that behavior.

0

Incidentally, here's some info that might help: My problem recurred when I updated to the latest version, 2019.2, build #IC-192.5728.98. My project was building fine before that. I got the Java version number to finally be respected, though I'm not sure how. But now my dependencies aren't being respected properly, either. IntelliJ can't find the jars for my dependencies, even though maven compiles everything just fine. Literally nothing changed except the version of IntelliJ that was installed. I've gone back through all the settings, and as far as I can tell, everything is set as it was before.

I have a deadline to meet, and suddenly I'm stranded. I don't have time to create a sample project that reproduces the issue. Even if I did, I wouldn't know how to reproduce the problem, because IDK what the heck is causing it. And the code I'm working on is proprietary, so I certainly can't upload it as-is. A little bit of understanding of the predicament we are placed in by being asked to prove the problem exists before getting help would go a long way.

0

This might help other people stumbling in the dark like me: https://stackoverflow.com/questions/27037657/stop-intellij-idea-to-switch-java-language-level-every-time-the-pom-is-reloaded

You can see there are a great variety of solutions for this problem. I'm not sure why there are so many ways for the same problem to be caused, but having the settings all in one place with a clear indication of where the final "winning" settings are taken from would eliminate a lot of confusion and frustration.

0

Any ideas how this is done if you have "preview" selected for "project language level"? Editing my pom keeps reverting back to 13 without preview features. I tried the following with no luck.

 

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>13</release>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
0

A related issue was addressed recently, but the fix is not released at the moment: https://youtrack.jetbrains.com/issue/IDEA-212618.

Wait for IntelliJ IDEA release build > 192.6478.

0

I have recently downloaded 193.6494.35 version and the problem is still present.
I configured source and target in the pom file but it wouldn't help.

2

Please sign in to leave a comment.