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


(Joby) #1

buildscript {
repositories.addAll(project.repositories)
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.12.1’
classpath ‘com.google.compile.js:closure-compiler:0.0.1.u’
}
}

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’
compilerOptions.setOutputCharset(“UTF-8”)
compilerOptions.setWarningLevel(com.google.javascript.jscomp.DiagnosticGroups.INTERNET_EXPLORER_CHECKS,com.google.javascript.jscomp.CheckLevel.OFF)
}
}
}

task individualMinify(dependsOn: tasks.matching { Task task ->
task.name.startsWith(“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.


(Stefan Oehme) #2

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.


(Joby) #3

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.


(Stefan Oehme) #4

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.


(Joby) #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.


(Stefan Oehme) #6

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