使用Gradle通过SCP上传

时间:2012-01-27 11:52:09

标签: build-automation gradle

在Gradle构建的Java模块中,我希望将项目生成的JAR上传到可通过SSH / SCP访问的远程位置。我找到的所有例子都不适用于我的环境。还有一个示例如何在Gradle教程中使用SCP:http://gradle.org/docs/current/userguide/maven_plugin.html(搜索“例38.4。通过SSH上传文件”)。 我稍微改编了一下这个例子,现在有了这个build.gradle:

apply plugin: 'java'
apply plugin: 'maven'

description = "User Service Implementation"

repositories {
    mavenCentral()
}

configurations {
    deployerJars "org.apache.maven.wagon:wagon-ssh:2.2"
}

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

uploadArchives {
    repositories.mavenDeployer {
        name = 'sshDeployer' // optional
        configuration = configurations.deployerJars
        repository(url: "scp://miniappserver") {
            authentication(userName: "root", password: "test")
        }
    }
}

但是当我测试那个脚本时,我收到了这个错误:

$ gradle uploadArchives -q

FAILURE: Build failed with an exception.

* Where:
Build file '/home/ifischer/git/userservice/implementation/build.gradle' line: 11

* What went wrong:
A problem occurred evaluating project ':implementation'.
Cause: Could not find method deployerJars() for arguments [org.apache.maven.wagon:wagon-ssh:2.2] on project ':implementation'.

我做错了什么?任何人都可以提供一个完整的工作示例吗?

[应将此问题发布到gradle-user邮件列表,但目前已关闭...]

1 个答案:

答案 0 :(得分:6)

正如Gradle Mailing列表上的回复(抱歉双重发布)我不得不删除配置任务中的"org.apache.maven.wagon:wagon-ssh:2.2"

(...)
configurations {
    deployerJars 
}
(...)