Gradle 创建可执行梯度任务

Gradle 创建可执行梯度任务,gradle,groovy,Gradle,Groovy,目前,我在gradle有一个类似这样的任务 class MyTask extends DefaultTask { @TaskAction public void run() { } } 我可以在build.gradle中做类似的事情 task stopTomcat(type:Exec) { workingDir '../tomcat/bin' //on windows: commandLine 'cmd', '/c', 'stop.bat' //

目前,我在gradle有一个类似这样的任务

class MyTask  extends DefaultTask {
    @TaskAction
    public void run() {

    }
}
我可以在build.gradle中做类似的事情

task stopTomcat(type:Exec) {
  workingDir '../tomcat/bin'

  //on windows:
  commandLine 'cmd', '/c', 'stop.bat'

  //on linux
  commandLine './stop.sh'

  //store the output instead of printing to the console:
  standardOutput = new ByteArrayOutputStream()

  //extension method stopTomcat.output() can be used to obtain the output:
  ext.output = {
    return standardOutput.toString()
  }
}

我想通过访问命令行、workingDir等使此任务可执行。我如何才能完成此任务?

您可以做这类事情(如果这是您的意思):


你说的可执行文件是什么意思?tim_yates,“访问命令行、工作目录等”是什么意思。在问题主体中添加了更多信息
class MyTask  extends DefaultTask {
    private workingDir
    private commandLine

    void workingDir(String workingDir) {
        this.workingDir = workingDir
    }

    void commandLine(String commandLine) {
        this.commandLine = commandLine
    }

    @TaskAction
    void run() {
        println "I will run $commandLine in $workingDir"
    }
}