gpt4 book ai didi

java - 如何在 gradle 任务中通过 scp 复制目录?

转载 作者:搜寻专家 更新时间:2023-10-30 20:59:19 25 4
gpt4 key购买 nike

用 Gradle 通过 scp 复制一堆文件的干净优雅的方法是什么?

目前我看到的两种方式是:

有没有更好(更明显)的方法来解决这个问题?

最佳答案

在最初的问题几年后,我喜欢 the Gradle SSH Plugin .其广泛的小引述documentation :

We can describe SSH operations in the session closure.

session(remotes.web01) {
// Execute a command
def result = execute 'uptime'

// Any Gradle methods or properties are available in a session closure
copy {
from "src/main/resources/example"
into "$buildDir/tmp"
}

// Also Groovy methods or properties are available in a session closure
println result
}

Following methods are available in a session closure.

  • execute - Execute a command.
  • executeBackground - Execute a command in background.
  • executeSudo - Execute a command with sudo support.
  • shell - Execute a shell.
  • put - Put a file or directory into the remote host.
  • get - Get a file or directory from the remote host.

...并允许,例如:

task deploy(dependsOn: war) << {
ssh.run {
session(remotes.staging) {
put from: war.archivePath.path, into: '/webapps'
execute 'sudo service tomcat restart'
}
}
}

关于java - 如何在 gradle 任务中通过 scp 复制目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13183433/

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