目前,我有一个任务要解决这样的问题

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等使此任务可执行。如何完成此任务?

最佳答案

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

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"
    }
}

关于gradle - 创建可执行的Gradle任务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43331144/

10-13 08:37