gpt4 book ai didi

gradle - Gradle Task:打开端口以用作TaskInput

转载 作者:行者123 更新时间:2023-12-03 03:09:34 24 4
gpt4 key购买 nike

希望根据开放端口获得任务输入和输出。

所以像

ext {
serverReady checkPortOpen()
}

task MyTask {
inputs.property ext.serverReady
outputs.property ext.serverReady
}

任何帮助或指示吗?

最佳答案

正如gradle文档中@Opal所指出的,有一个output.upToDate可以完美地完成这项工作。

在运行完整的测试套件之前,我需要启动一些服务,因此我有一个:

 class BaseServiceTask extends com.github.jengelman.gradle.plugins.processes.tasks.JavaFork {
def BaseServiceTask() {
super()
classpath project.configurations.all
args ["-user","user","-password","password","-env","mydevenv"]
}
}

task startServer (type:BaseServiceTask) {
main = "com.nico.StartServer"
jvmArgs += ["-Xmx8096m","-XX:MaxPermSize=256m"] // give more memory to data server
outputs.upToDateWhen { checkSocket(servicePort) }
doLast {waitForSocket(servicePort)}
}

和较低的细节...
def checkSocket(portS) {
try {
new Socket("localhost", portS.toInteger())
return true
} catch (Exception e) {
return false
// throw new GradleScriptException("Required ${portS} is closed", e )
}
}

def waitForSocket(portS) {
while(!checkSocket(portS)) {
println "Waiting on ${portS}"
Thread.sleep(5000)
}
}

最后,在运行相关的gradle任务时,输出应正确地保持最新状态:
 :startServer UP-TO-DATE

关于gradle - Gradle Task:打开端口以用作TaskInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27033290/

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