Question

I have defined a simple Gradle task of type Exec and I'm trying to pass a parameter to that task when calling it from another task.

How does one do that ?

Was it helpful?

Solution

It isn't possible to call a task from another task. Instead, declare two tasks and make one depend on the other. (Calling the internal task.execute() method is unsupported, and its behavior is undefined.) For cases where having a second task isn't feasible, there is a project.exec {} method, which has exactly the same API as the task.

OTHER TIPS

As it has been pointed out my initial approach was flawed and not "the gradle way". So after carefully rethinking the problem I turned everything upside down and now I "just" loop through my arguments and in turn execute the code for each argument.

Case here is a list of languages that each will be used as an argument in a command line.

task multiCommands << {
  def lang = languages.split()
  lang.each { locale -> 
    def output = exec {
      commandLine "my command that takes an argument", locale
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top