Fix Gradle Eclipse task ignoring JAVA_HOME

I started playing with Java again recently and lost quite a bit of time fixing a stupid issue: when running a Gradle task from Eclipse, Gradle was ignoring JAVA_HOME environment variable. Here is how I fixed that issue.

The issue

When installing Java 8, I decided to install both the JRE and the JDK (in that order). Looks like Java now creates a symlink from C:\ProgramData\Oracle\Java\javapath to your Java bin directory and puts that as the first entry in the PATH environment variable. Doing so makes your first Java installation be your default installation.

I could not find a clean way to modify this behavior or to change the path in C:\ProgramData\Oracle\Java\javapath. Yeah, sure, I could simply modify it or remove it from the path, but without being certain that it won’t break anything I did not want to change it.

As a second issue, it looks like Eclipse ignores the Gradle wrapper (gradlew.bat on windows) or eats the environment variable. If it was using the wrapper, you’d be able to change the Java used by using the JAVA_HOME environment variable.

The fix

I decided to go the easy route and simply add my java installation into the path (as the first entry). I really don’t like this solution, it pollutes my path and prevents me from easily switching. I’ll continue to investigate why Eclipse eats the configuration and update this post (or link to a new one) once I get something cleaner.


Tagged , . Bookmark the permalink.

Leave a Reply