Is there a way to invoke some tasks in a build.gradle with a different JAVA_HOME.?

buildscript {
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.12.1’
classpath ‘’

apply plugin: “com.eriwen.gradle.js”

def temporaryDirJS

task copyResources {
copy {
from 'WebContent/js’
into “$temporaryDir"
doLast {
ant.chmod(dir: “$temporaryDir”, perm:“755”,includes:”*")
temporaryDirJS = “$temporaryDir”

task JSMinification() {
FileTree sourceTree = fileTree(dir: “$temporaryDirJS”)
sourceTree.eachWithIndex { jsFile, idx ->
project.tasks.create(name: “dominify${idx}”, type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
source = jsFile
dest = jsFile
closure {
warningLevel = 'QUIET’
compilationLevel = 'WHITESPACE_ONLY’

task individualMinify(dependsOn: tasks.matching { Task task ->“dominify”)} )

This task fails if the JAVA_HOME is pointing JDK5. Since google compiler is compiled with Java 7. With Java5 I am getting “Caused by: java.lang.UnsupportedClassVersionError: (com/google/javascript/jscomp/DiagnosticGroups) bad major version at offset=6”. Is there a way to run these tasks alone with JAVA7 jvm. I can not move the whole build to Java7 as the requirement is to Compile the class files in JDK5.0.

You don’t need to run your build on Java 5 to compile the classes for Java 5. That’s a common misconception.

You can set the sourceCompatibility property to 1.5 and run your build on Java 8 for instance.

Thanks for the reply… Just looking for some option like GradleBuild task or Fork task to do this.? I am trying on that way, but no luck for now. Would be grateful with any sort of help.

You just use

apply plugin: 'java'
sourceCompatibility = '1.5'

and run your build in Java 7 or 8. The compiled code will still run on Java 5.

Due to some project specific reasons I am forced to use JDK5. So sourceCompatibility is not possible to use. So I am almost struck.

Maybe @eriwen has an idea how to fork the closure-compiler.