Gradle 2.13 hooks up the wrong JRE

eclipse

(MJ) #1

I recently updated my Gradle to 2.13 and it doesn’t work like the previous version that I used. In my build.gradle files, I use the following setting:

sourceCompatibility = 1.6

This is because I’m maintaining a library that should be backwards-compatible. When I was using gradle eclipse command to generate Eclipse project, it used to set compliance level to 1.6 (as expected), and hook up my system Java 8 JRE library, thus generating no warnings.

However, the new Gradle version hooks up JRE System Library [JavaSE-1.6], which generates the following warning:

Build path specifies execution environment JavaSE-1.6. There are no JREs installed in the workspace that are strictly compatible with this environment.

I know how to remove the warning manually (remove the incorrect system library, add default Java 8 system lib), but I want to know if there’s a way of achieving the previous Gradle behavior without
having to modify anything in the IDE itself.


(Stefan Oehme) #2

This warning is correct, you are using a Java 8 JDK, which contains classes that are not present in Java 6. As a result you would be able to write code that will not run under Java 6. The correct fix is to add a Java 6 JDK to the Execution Environments in your workspace preferences.


(MJ) #3

Well, you’re kind of right, but then again - JRE 8 system lib is working just fine and I do get warnings when I use forbidden, post-1.6 features even with the 1.8 system library attached. I think the most important setting is the compliance level of the project.

When you set up the compliance level to 1.6, as far as I know you can use a newer JDK and the jars still get built correctly. I’ve use this setup for quite a while and never experienced any problems.

The thing is: previous Gradle version hooked up my system JRE library, regardless of its level - which was completely fine with me. The new one forces JRE library that I don’t even have, hence the warning.

I found a topic about a similar problem with Maven here, but their proposed solution is attaching the system library manually in IDE. When working with different branches, I usually run the eclipse task after checkout, so I don’t really want to spend my time on manually setting up several projects.


(MJ) #4

Maybe I should rephrase the question: is there a way to force Gradle to hook up a specific JRE system library when generating a new Eclipse project with the standard eclipse plugin? In my case, I want it to use the library from JRE located at JAVA_HOME rather than forcing a library according to sourceCompatibility setting.


(Stefan Oehme) #5

That’s only true for language features, but not for classes. If you have JDK 8 on the classpath, you can access things like java.util.function and you won’t get a warning.

Which was incorrect and caused many users problems.

If you really don’t care about using the correct JDK, you can deactivate this warning in the workspace settings (Java -> Compiler -> Building -> No strictly compatible JRE). I strongly recommend using the correct JDK though.


(MJ) #6

I’ll take my changes with the new JDK. Thank you for your reply.