I am trying to build a custom Gradle Task to perform some app maintenance operations. I would like to pass argument(s) to the task to control operations. To illustrate my dilemma, consider to following two trivial custom task classes:
// Custom task with no arguments
public class HelloClassA extends DefaultTask {
@TaskAction
public void printHello()
{
println "Hello, World!"
}
}
// Custom task with one argument
public class HelloClassB extends DefaultTask {
@TaskAction
public void printMsg(String msg)
{
println msg
}
}
They are identical except that "A" prints a hard-coded string while "B" accepts a string as an argument.
Class A is used in the following task:
task helloA(type:HelloClassA) { }
and is invoked by, e.g.,
gradlew.bat helloA
It works fine and prints "Hello, World!" to the Build window. However, I can't figure out the syntax is for a task to invoke Class B.
How do I do that? (or am I just way off base trying to do it this way?)
Some rather Strange Things I've noticed...
- The name of the method in the classes (e.g., "printHello") seems to be irrelevant: any reasonable name produces identical output (?).
- When invoking by gradlew.bat, any unambiguous substring of the task name works the same, e.g., "GRADLEW helloA" or "GRADLEW hell". I guess this is just GRADLE trying to be helpful (?).