4

I have a gradle project which I want to upload to a private remote maven repository using SCP with a private key. How to do this?

R Gastmeier
  • 101
  • 6

1 Answers1

4

In your Gradle build file (build.gradle), add the following:

apply plugin: 'java'
apply plugin: 'maven' // you need this plugin for mavenDeployer support

// here you specify how the dependency is going to be retreived
// for example:
// compile group: 'co.domain', name: 'library', version: '0.1'
group = 'co.domain'
rootProject.name = 'library'
version = '0.1'

task deployJar(type: Jar)

configurations {
    deployerJars
}

dependencies {
    deployerJars "org.apache.maven.wagon:wagon-ssh:2.9"
}

uploadArchives {
    repositories.mavenDeployer {
        configuration = configurations.deployerJars
        repository(url: "scp://<url-of-your-webserver>/<path-to-maven-directory>") {
            authentication(userName: "ssh-username", privateKey: "<path-to-private-key-file")
        }
    }
}

The repository url could look something like this:

scp://domain.co/var/www/maven/

And the privateKey path could look something like this:

/home/users/username/.ssh/id_rsa

For more insights on how to publish artifacts in Gradle, look here: Publishing artifacts

And then look here for Maven specifics: The Maven Plugin

R Gastmeier
  • 101
  • 6