从 Gradle 上传一个 RPM 到 Artifactory

Upload an RPM to Artifactory from Gradle

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

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

我假设您正在使用 Gradle ospackage plugin 并且已经创建了一个 RPM 版本。在我的例子中,RPM 任务的名称是 distRpm。例如:

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

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

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 的确切文件名。

这是我使用 Gradle Artifactory 插件

的代码片段

应用插件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.0"
    }
}

apply plugin: 'ivy-publish'
apply plugin: 'com.jfrog.artifactory'

配置神器

artifactoryPublish {}.dependsOn(buildRpm)

publishing.publications.create('yum-publication', IvyPublication) {
        artifact buildRpm.outputs.getFiles().getSingleFile()
}



artifactory {
    contextUrl = 'https://artifactory.acme.com/artifactory'   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        //A closure defining publishing information
        repository {
            repoKey = 'demo-yum'   //The Artifactory repository key to publish to
            username ="${artifactory_user}"
            password = "${artifactory_password}"
            ivy {
                 artifactLayout = "${buildRpm.outputs.getFiles().getSingleFile().getName()}"
            }
        }
        defaults {
            //List of Gradle Publications (names or objects) from which to collect the list of artifacts to be deployed to Artifactory.
            publications ('yum-publication')

            publishBuildInfo = false   //Publish build-info to Artifactory (true by default)
            publishArtifacts = true   //Publish artifacts to Artifactory (true by default)
            publishPom = false   //Publish generated POM files to Artifactory (true by default).
            publishIvy = false   //Publish generated Ivy descriptor files to Artifactory (true by default).
        }
    }
}