Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

java - How to copy directory via scp within gradle task?

What is a clean and elegant way to copy a bunch of files via scp with Gradle?

Two ways I currently see are:

Are there any better (more obvious) ways to approach this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A few years after the original question, I like the Gradle SSH Plugin. A small quote of its extensive 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.

...and allows for, for example:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...