Hi all,
I tried to use the JAVA_HOME environment variable inside a build script to exec the xjc tool from the JDK. This worked fine from the Windows command shell, but failed when called from the Cygwin shell. Apparently, the “gradle” shell script (from the Gradle bin folder) modifies the JAVA_HOME environment variable.
The build file (simplified):
task printXjcVersion << {
exec {
commandLine(
System.getenv(“JAVA_HOME”) + “/bin/xjc.exe”,
“-version”
)
ignoreExitValue = true
}
}
The output from the Windows shell:
C:>gradle -q printXjcVersion
xjc 2.2.4-2
The output from the Cygwin shell:
$ gradle -q printXjcVersion
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ‘:printXjcVersion’.
A problem occurred starting process ‘command ‘/cygdrive/c/Program Files/Java/JDK1.7.0_11/bin/xjc.exe’’
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
So the problem is that the cygwin-ified version of JAVA_HOME is useless outside of the starter script. I devised a simple fix for the gradle shell script. The idea is to modify the JAVACMD local variable instead of JAVA_HOME. This works for me. I’m not a shell expert, though.
The output from the Cygwin shell with my fix:
$ gradle -q printXjcVersion
xjc 2.2.4-2
I’m using Gradle 1.4 on Windows. I attached my simple patch.
Regards Jörg