Pass parameters to task


(kshaw) #1

I want to effectively invoke a task multiple times with different values each time. How can I do this? Or what is a better way? Can a task be passed parameters? Or, configured and run multiple times, or something else? For example:

task abc << {

println “$x $y” }

Have different values for x and y when the task is executed.

The real thing I’m trying to do at the moment is create a JavaExec task that can be reused with different inputs and outputs each time.


(Szczepan Faber) #2

Gradle won’t let you run the same task multiple times within a single build.

The solution to your problem is to create a task instance for every set of inputs. Alternatively you can use task rules (see the user guide for more info).

Hope that helps!