Gradle使用scp和私钥发布到maven存储库

时间:2015-05-29 12:17:28

标签: gradle scp public-key maven-publish

我有一个gradle项目,我希望使用带有私钥的SCP上传到私有远程maven存储库。怎么做?

1 个答案:

答案 0 :(得分:3)

在Gradle构建文件(build.gradle)中,添加以下内容:

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")
        }
    }
}

存储库网址可能如下所示:

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

privateKey路径看起来像这样:

/home/users/username/.ssh/id_rsa

有关如何在Gradle中发布工件的更多见解,请查看此处:Publishing artifacts

然后在这里查看Maven细节:The Maven Plugin