【发布时间】:2023-04-03 07:20:01
【问题描述】:
我想要一个 Gradle Tasks 来执行我新构建的 Java 应用程序。它还应该将 log/sout 输出到一个名为 servicedispatcher.out 的文件中。发生的问题是Gradle,即使我让这个任务依赖于copyDistributionsToDestination(这会创建错误抱怨的丢失文件路径),它仍然会在任务依赖之前评估任务代码。这样我就没有机会将此路径定义为日志输出路径。我能做些什么来解决这个问题?
给定以下代码:
task startDispatcher(type:Exec){
workingDir = "servicedispatcher/bin/"
commandLine "cmd", "/c", "servicedispatcher.bat"
File logFile = file("${workingDir}/log/toolbox-components-servicedispatcher.out")
if(logFile.exists() == false){
logFile.createNewFile() // Line 75 of error message
}
standardOutput = new FileOutputStream("${workingDir}/log/servicedispatcher.out")
}
task startToolbox(){
group "Toolbox"
dependsOn copyDistributionsToDestination
dependsOn startDispatcher
}
startDispatcher.mustRunAfter("copyDistributionsToDestination")
错误信息:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Development\Testzone\toolbox-backend\build.gradle' line: 75
* What went wrong:
A problem occurred evaluating root project 'toolbox-backend'.
> Das System kann den angegebenen Pfad nicht finden
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.32 secs
Das System kann den angegebenen Pfad nicht finden
19:19:48: External task execution finished ':startToolbox'.
【问题讨论】: