Using SSH with Gradle

Today one point of the agenda was to upload an OSGi Library to a remote server. The Gradle SSH Plugin to the rescue. First we create a Gradle configuration - this is usually a file:

# sftp server url

# sftp username

# sftp username

# absolute path to the root of the update-sites mirror

In the build file responsible for uploading the OSGi bundles upload.gradle we use the properties defined above to configure the SSH Plugin. Most note worthy in here: Referencing the user's home directory in a Gradle script.

plugins { id 'org.hidetake.ssh' version '1.1.4' }

remotes {
  datenkollektivDe {
    host = FTP_HOST
    user =  FTP_USER
    identity = file(['user.home'] + "/.ssh/${FTP_IDENTITY}")
    knownHosts = file(['user.home'] + "/.ssh/known_hosts")

The remaining part of the script is pretty straight forward:

task uploadOSGiBundle << { {
    session(remotes.datenkollektivDe) {
      execute "mkdir -p ${FTP_MIRROR_PATH}"
      put from: "${buildDir}/planets-homepage.jar", into: "${FTP_MIRROR_PATH}"
Show Comments