Resetting the UP-TO-DATE property of gradle tasks?
Try to run your build with -C rebuild that rebuilds Gradle’s cache. In newer versions of Gradle, use –rerun-tasks
Try to run your build with -C rebuild that rebuilds Gradle’s cache. In newer versions of Gradle, use –rerun-tasks
Use this: def map = [(A):1, (X):2] For the value-part it’s even easier, since there is no automagic “convert text to string” happening: def map = [keyA:A, keyX:X]
A source release will be compiled on your own machine while a binary release must match your operating system. source releases are more common on linux systems because linux systems can dramatically vary in cpu, installed library versions, kernelversions and nearly every linux system has a compiler installed. binary releases are common on ms-windows systems. … Read more
In a Groovy script the scoping can be different than expected. That is because a Groovy script in itself is a class with a method that will run the code, but that is all done runtime. We can define a variable to be scoped to the script by either omitting the type definition or in … Read more
Nope, you can’t abort an “each” without throwing an exception. You likely want a classic loop if you want the break to abort under a particular condition. Alternatively, you could use a “find” closure instead of an each and return true when you would have done a break. This example will abort before processing the … Read more
To determine the class of an object simply call: someObject.getClass() You can abbreviate this to someObject.class in most cases. However, if you use this on a Map it will try to retrieve the value with key ‘class’. Because of this, I always use getClass() even though it’s a little longer. If you want to check … Read more
I usually throw the relevant exception from the org.gradle.api package, for example InvalidUserDataException for when someone has entered something invalid, or GradleScriptException for more general errors. If you want to stop the current task or action, and move on to the next, you can also throw a StopActionException
It’s syntactic sugar for basic scripts. Omitting the “def” keyword puts the variable in the bindings for the current script and groovy treats it (mostly) like a globally scoped variable: x = 1 assert x == 1 assert this.binding.getVariable(“x”) == 1 Using the def keyword instead does not put the variable in the scripts bindings: … Read more
Ok, solved it myself; def sout = new StringBuilder(), serr = new StringBuilder() def proc=”ls /badDir”.execute() proc.consumeProcessOutput(sout, serr) proc.waitForOrKill(1000) println “out> $sout\nerr> $serr” displays: out> err> ls: cannot access /badDir: No such file or directory
Use the toInteger() method to convert a String to an Integer, e.g. int value = “99”.toInteger() An alternative, which avoids using a deprecated method (see below) is int value = “66” as Integer If you need to check whether the String can be converted before performing the conversion, use String number = “66” if (number.isInteger()) … Read more