从 Gradle 上传 RPM 到 Artifactory [英] Upload an RPM to Artifactory from Gradle

查看:45
本文介绍了从 Gradle 上传 RPM 到 Artifactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Gradle 将 RPM 文件上传到 Artifactory?Gradle 总是使用 maven 风格的直接布局上传文件,这不适用于 YUM 存储库.

How can I upload an RPM file to Artifactory using Gradle? Gradle always uploads the files using a maven-style directly layout which is inappropriate for a YUM repository.

推荐答案

这里的问题是 Gradle 坚持以 group-id/version/artifact 的 maven 风格目录格式上传所有内容,而 yum 存储库需要平面布局.这里有两种方法 - 使用 Artifactory 插件或 Gradles 较新的发布机制.我只能让它与后者一起工作.

The issue here is that Gradle insists on uploading everything in a maven-style directory format of group-id/version/artifact, while a yum repository needs a flat layout. There are two approaches here - using the Artifactory plugin or Gradles newer publishing mechanism. I could only get this to work with the latter.

我在这里假设您正在使用 Gradle ospackage 插件并且已经创建了一个 RPM 构建.在我的例子中,RPM 任务的名称是 distRpm.例如:

I assume here that you're using the Gradle ospackage plugin and already have an RPM build created. In my case the name of the RPM task is distRpm. For example:

task distRpm(type: Rpm) {
    packageName = 'my_package'
    version = version
    release = gitHash
    arch = 'X86_64'
    os = 'LINUX'
    // Etc
}

将 ivy 发布插件添加到您的项目中:

Add the ivy publish plugin to your project:

apply plugin: 'ivy-publish'

然后添加一个发布块:

publishing {
    publications {
        rpm(IvyPublication) {
            artifact distRpm.outputs.getFiles().getSingleFile()
            /* Ivy plugin forces an organisation to be set. Set it to anything
               as the pattern layout later supresses it from appearing in the filename */
            organisation 'dummy'
        }
    }
    repositories {
        ivy {
            credentials {
                username 'yourArtifactoryUsername'
                password 'yourArtifactoryPassword'
            }
            url 'https://your-artifactory-server/artifactory/default.yum.local/'
            layout "pattern", {
                artifact "${distRpm.outputs.getFiles().getSingleFile().getName()}"
            }
        }
    }
}

Ivy Publication 允许您指定上传的目录和文件名模式.这将被覆盖为只是 RPM 的确切文件名.

The Ivy Publication allows you to specify the directory and filename pattern for upload. This is overwritten to be simply the exact filename of the RPM.

这篇关于从 Gradle 上传 RPM 到 Artifactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆