如何使用 gradle 将文件上传到 artifactory 通用存储库?

How to upload file to artifactory generic repository with gradle?

我使用 gradle 构建应用程序分发,其中 tar 文件包含所需的一切。我在 artifactory 中创建了一个通用存储库。我想将 tar 球上传到通用存储库。

通过查找此文档 http://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin

我没有找到这样做的方法。 我是新手 gradle 和 artifactory 用户,谁能给我指导。

task uploadDistroTar(type: org._10ne.gradle.rest.RestTask) {
    httpMethod = 'PUT'
    uri = 'http://x.x.x.x:8081/artifactory/repo/foo.tar'
    username = 'admin'
    password = 'passwd'
    requestContentType = groovyx.net.http.ContentType.BINARY
    requestBody = new File("build/distributions/foo.tar").bytes
}

最简单的方法是使用 Gradle REST plugin。只需使用 PUT 请求将文件上传到您想要的存储库。

最后我通过阅读插件的源代码找到了解决方案, 刚刚设置:

preemptiveAuth = true

更现代的解决方案是使用 Artifactory Java Client:

Artifactory artifactory = ArtifactoryClientBuilder.create()
    .setUrl("ArtifactoryUrl")
    .setUsername("username")
    .setPassword("password")
    .build();

java.io.File file = new java.io.File("fileToUpload.txt");
File result = artifactory.repository("RepoName").upload("path/to/newName.txt", file).doUpload();