Doing rsync from Gradle build

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

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.

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?

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.

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?

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 (https://github.com/tobiasbaum/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.

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)?

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: https://github.com/tobiasbaum/jsync/blob/master/src/main/java/de/tntinteractive/jsync/JsyncClient.java

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.

Neither jarsync nor java-rsync are under active development.

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 {
    mavenCentral()
}
  configurations {
    antScp
}
  dependencies {
    antScp "org.apache.ant:ant-jsch:1.9.2"
}
  ant.taskdef(
    name: 'scp',
    classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
    classpath: configurations.antScp.asPath
)
  task deploy {
    doLast {
        ant.scp(
            file: file("$buildDir/my_file"),
            remoteToFile: "user@mybiz.com:www/my_file_renamed",
            keyfile: "/Users/user/.ssh/id_rsa",
            passphrase: "your_secret_passphrase"
        )
    }
}

See http://ant.apache.org/manual/Tasks/scp.html For details on how to use the scp ant task.