문제

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 ?

도움이 되었습니까?

해결책

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.

다른 팁

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
    }
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top