How Do I Use Different Compilers in the Same Build?


(rc) #1

I’m switching over from a large set of Ant build scripts to Gradle. I have a set of projects, a few of them are built using standard Java 7 JDK, the others use the WebSphere Application Server JDK which is Java 6. The projects that are built using Java 7 need Java 7. The projects that are built using WebSphere Java 6 cannot be built with Java 7 since the WAS JDK provides links to a lot of WAS-specific libraries during compile-time by default and I don’t know what they all are, so I’d rather not search through the WAS JDK to link to those libraries.

I am able to switch to either JDK using gradle.properties and the org.gradle.java.home setting, but cannot do so for specific projects. This forces me to do these builds separately. Is there a way to switch compilers for specific projects mid-build?


(Gary Hale) #2

Take a look at the JavaCompile task, options -> forkOptions. This should allow you to fork the compiler and set the executable to whichever you want to use.