使用 Gradle 通过 SCP 上传

发布于 2024-12-29 13:47:31 字数 1383 浏览 1 评论 0原文

在 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 用户邮件列表,但目前已关闭...]

Inside a Java module build by Gradle, I want to upload the resulting JAR(s) of my project to a remote location which is reachable via SSH/SCP. All examples I found did not work inside my environment. There is also an example how to use SCP inside the Gradle tutorial: http://gradle.org/docs/current/userguide/maven_plugin.html (search for "Example 38.4. Upload of file via SSH").
I adapted the example a bit and now have this 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")
        }
    }
}

But when I test that script I'm getting this error:

$ 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'.

What am I doing wrong? Can anybody provide a complete working example?

[should post that question to the gradle-user mailing list, but it's currently down...]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2025-01-05 13:47:31

正如 Gradle 邮件列表上的友好回复(抱歉重复发帖),我必须删除配置任务中的 "org.apache.maven.wagon:wagon-ssh:2.2"

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

As kindly replied on the Gradle Mailing list (sorry for double posting) I had to remove the "org.apache.maven.wagon:wagon-ssh:2.2" inside the configurations-task:

(...)
configurations {
    deployerJars 
}
(...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文