How do I configure OS-specific Java Home at project level?

(Mike Snare) #1

I’m re-writing our windows-based build system in gradle, and one of the goals is to enable Mac development – but windows development still needs to work.

I want to make sure that all developers are using the same version of Java, so I don’t want to leave setting the property to developers in their respective files under their home directories.

The settings for what java to use should therefore be specific to the project, ideally committed to source control.

Since is just a flat file I can’t use any logic in there to pick a java home based on the current platform.

It’s possible to set the executable for javac inside the build files, but when I’ve done that I’ve run into problems because some libs that we compile against from the JDK weren’t available. I was unable to find a solution that fixed that problem on both platforms.


What’s the recommended approach for this scenario? Customizing the gradlew.bat and gradlew scripts? Is there some other magic that allows the java home for the build itself to differ from the java home used by the forked javac?

Thanks in advance