0
votes

Not able to set command line arguments while configuring subprojects' task.

task doStuff {
    def executable_task = project(':SubProject1').getTasksByName('run',true)
    println executable_task.name
    println executable_task.args
    executable_task.args('xyz')
}

This error message is being showed:

What went wrong: A problem occurred evaluating root project 'MainProject'. No signature of method: java.util.HashSet.args() is applicable for argument types: (java.lang.String) values: [xyz] Possible solutions: any(), grep(), grep(), add(java.lang.Object), add(java.lang.Object), is(java.lang.Object)

1

1 Answers

-1
votes

The method Project.getTasksByName() returns a Set of Task instances. You will need to assign the field to each element in the Set.

task doStuff {
    doLast {
        Set<Task> executableTasks = project(':SubProject1').getTasksByName('run', true)
        executableTasks.each {
            it.args 'xyz'
        }
    }
}

BTW: I don't understand why you need to set arguments for a task in a different project. Couldn't you just set it in the subproject :SubProject1 that defines the task? I'd actually set the task properties within :SubProject1 with a configuration rule:

tasks.withType(JavaExec).matching { it.name == 'run' }.each { it.args 'xyz' }