4

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

4

1 回答 1

4

在您的 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")
        }
    }
}

存储库 url 可能如下所示:

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

privateKey 路径可能如下所示:

/home/users/username/.ssh/id_rsa

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

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

于 2015-06-04T09:43:53.753 回答