您陷入了在中执行逻辑的常见错误
configuration
execution
阶段
试试这个
task copyToLib(type: Copy, dependsOn: classes) {
...
doLast {
ext.serverPath = ...
}
}
如果是我,我会计算
serverPath
run
而不是在
copyToLib
. 也许你需要一个
closure
task run(type: Exec, dependsOn: [copyToLib, war]) {
def pathClosure = {
fileTree("$buildDir/server/").include("webapp-runner-*.jar").singleFile
}
mustRunAfter copyToLib
executable 'java'
args '-jar', pathClosure, war.archivePath, '--port', "$port"
}