gpt4 book ai didi

gradle - 创建可执行的Gradle任务

转载 作者:行者123 更新时间:2023-12-03 03:28:42 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com