从Gradle将一个RPM上传到Artifactory

5
我该如何使用Gradle上传RPM文件到Artifactory?Gradle始终会使用适用于Maven的直接布局来上传文件,这对于YUM库是不合适的。
2个回答

5
这里的问题在于Gradle坚持以maven风格的目录格式group-id/version/artifact上传所有内容,而yum仓库需要一个平面布局。这里有两种方法-使用Artifactory插件或Gradle的新发布机制。我只能用后者使其工作。
我假设您正在使用Gradle ospackage插件并且已经创建了一个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的确切文件名。


1
我采用了这种方法,解决了“Gradle尝试将RPM上传到Artifactory YUM仓库两次”的问题。http://stackoverflow.com/questions/40001668/gradle-publish-attemps-to-upload-rpm-to-artifactory-yum-repo-twice-second-time#comment69674847_40001668 - qwazer
1
这是一个不好的解决方案,因为当使用多个出版物或像@popalka一样上传多个工件时,它将会出问题。你应该使用真正的模式来代替硬编码预期单个文件的名称。 - Lukas Körfer
2
由于Gradle中尚未实现Ivy占位符[originalname],因此您应该使用另一个占位符(例如[module])并将文件名放入该属性中。请查看这个最小示例 - Lukas Körfer

1
这是使用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'

配置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).
        }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接