Doing rsync from Gradle build

(steve) #1

How would one accomplish doing an rsync from a Gradle build script?

(Peter Niederwieser) #2

If it’s good enough to have it work on *nix, you could use an ‘Exec’ task. Otherwise, consider using a Java library like JarSync or java-rsync.

(steve) #3

Thanks Peter.

I guess I’ll just have to go the exec route. Neither library you mentioned seems to be really active anymore and java-rsync does not even have a downloadable release.

Any plans for Gradle to incorporate rsync/sftp support?

Possible to embed ruby calls?

(Peter Niederwieser) #4

I’m not aware of concrete plans to add rsync/sftp support, though we might accept contributions. This would also do well as a third-party plugin, especially once the plugin portal is out.

You can always exec out to Ruby. I haven’t tried running JRuby in the Gradle JVM.

(Michael Brand) #5

Is there a feature request for this? Chasing this down has been a huge issue for me. We have people running over very slow networks need an efficient way to transfer from a Windows, Mac, or Linux client to a Unix server.

I have run JRuby from Gradle to support Compass/SASS, but I don’t have much experience with JRuby. How would you use JRuby to accomplish this?

(tbaum) #6

If you just need a solution to efficiently sync remote directories (and don’t need binary compatibility with rsync) you can have a look at jsync ( I developed it after being quite unsatisfied with the solutions provided in this thread so far. It’s pure Java and the client calls can be used from Gradle easily (after all that’s its main purpose), but be aware that it’s still rather fresh and not a full fledged rsync replacement.

(steve) #7

Tobias, your wiki mentions command line usage and needing to start a daemon first manually. How would one use this from a Gradle build (or other “embeded” uses)?

(tbaum) #8

For the client: You can call de.tntinteractive.jsync.JsyncClient.syncDirectory(File localDirectory, String remoteHost, int remotePort, String remoteParentDirectory) from Gradle. You could have a look at the source for further details:

For the daemon: Currently, I don’t have the need to start the daemon from a build because I can keep them running. But the daemon could probably be started using the SSH task or something similar.

(Jason Zwolak) #9

Neither jarsync nor java-rsync are under active development.

(Jason Zwolak) #10

scp can be used through Ant, although this doesn’t have the power of rsync. But it satisfies the question about sftp earlier in the thread.

repositories {
  configurations {
  dependencies {
    antScp "org.apache.ant:ant-jsch:1.9.2"
    name: 'scp',
    classname: '',
    classpath: configurations.antScp.asPath
  task deploy {
    doLast {
            file: file("$buildDir/my_file"),
            remoteToFile: "",
            keyfile: "/Users/user/.ssh/id_rsa",
            passphrase: "your_secret_passphrase"

See For details on how to use the scp ant task.