Calling "gradle(w)" in batch files on Windows gives weird/inconsistent results

(frederick.deschenes) #1

Hi guys!

I’m having some issues with Gradle acting differently depending on how it is launched.

This is my setup : Groovy: 1.8.6 Ant: Apache Ant™ version 1.8.4 compiled on May 22 2012 Ivy: 2.2.0 JVM: 1.7.0_10 (Oracle Corporation 23.6-b04) OS: Windows 7 6.1 amd64

The issue happens with both Gradle and the Gradle wrapper, version 1.3, 1.4 and 1.5.

build.gradle content :

task printSomething() << {
  println "This is inside the Gradle script"
   //Using the wrapper or a regular Gradle install doesn't change anything, I'm just putting this here because it's
 //in my build file
task wrapper(type: Wrapper) {
  description = "Sets up the Wrapper files"
 gradleVersion = "1.5"

And here is my test batch file’s contents :

Basically, when called from a batch file with the daemon option, lots of different things can happen: - If called from a CMD window (“gradle taskName”), everything seems to work as expected. - If called inside a batch file, the CMD window is killed right after the Gradle call, nothing after in the script is executed. - If called inside a batch file from another batch file that is ran (double click), the CMD window is also killed. - If the batch file is called from a CMD window, the window is not killed but still exits right after the Gradle call, before the rest of the script is ran.

I have tried 'start’ing and 'call’ing Gradle, with even weirder results (you can see those and their results in the Gist).

I’m not sure if this is related at all, but I think this has caused some issues for us when trying to build AIR applications while having Gradle setup to only load the dependencies, letting FlashDevelop/FlexSDK handle the actual build.

Basically, MXMLC (the Flex compiler) is called right after the dependencies are loaded with the Gradle daemon. The build’s output is always a 0 byte SWF file. When running without the daemon, everything works as expected, but obviously takes longer.

I have currently simply disabled the daemon from by batch file and everything works fine, but would love to be able to re-enable it for the speed boost. I’m aware of GradleFX and use it on other projects, I just thought this was somewhat overkill for the project I’m having issues with.

Thanks for your help!

EDIT : I just realized that using the daemon has nothing to do with this, simply calling ‘gradle(w) myTaskName’ in a batch file will reproduce this.

(randy.holiman) #2

I suspect you are getting that result because you are not using the windows call command. If you call a batch command from another batch command, it runs it in the same shell by default. When the called batch command completes, the shell terminates. Since it is running in the same shell as the main script, it terminates the main script too. If you use the call command, it creates a subshell to run the batch command. When the subshell terminates, it will return and execute the next command in the main script.