我有以下要转换为 groovy 的 Java 代码:
String containerId = "545cdc81a969";
ExecCreateCmdResponse execCreateCmdResponse = dockerClient
.execCreateCmd(containerId)
.withAttachStdout(true)
.withCmd("sh", "-c", "sleep 5 && exit 5")
.exec();
ExecStartResultCallback execStartCmd =
dockerClient.execStartCmd(execCreateCmdResponse.getId())
.exec(new ExecStartResultCallback(System.out, System.err))
.awaitCompletion();
我当前的 groovy 版本是这样的:
String id = "545cdc81a969";
def execCreateCmdResponse = dockerClient
.execCreateCmd(id)
.withAttachStdout(true)
.withCmd('sh','-c','sleep 5 && exit 5')
.exec()
dockerClient.execStartCmd(execCreateCmdResponse.getId())
.withDetach(false)
.exec(new ExecStartResultCallback(System.out, System.err))
.awaitCompletion()
我的问题是,当我尝试运行 groovy 代码时出现以下错误:
* What went wrong:
Execution failed for task ':werner'.
> No signature of method: com.github.dockerjava.core.command.ExecStartCmdImpl.exec() is applicable for argument types: (com.github.dockerjava.core.command.ExecStartResultCallback) values: [com.github.dockerjava.core.command.ExecStartResultCallback@6ce82155]
Possible solutions: exec(com.github.dockerjava.api.async.ResultCallback), exec(com.github.dockerjava.api.async.ResultCallback), every(), grep(), every(groovy.lang.Closure), grep(java.lang.Object)
Java-exec-Method 具有签名:
public <T extends ResultCallback<Frame>> T exec(T resultCallback);
我尝试将“new ExecStartResultCallback(System.out, System.err)”转换为“ResultCallback”,但没有成功。
有什么方法可以强制 Groovy 将实例作为 ResultCallback-Instance 处理,以便调用正确的方法?
问候,马本