【问题标题】:Upload an RPM to Artifactory from Gradle从 Gradle 将 RPM 上传到 Artifactory
【发布时间】:2016-11-09 23:34:36
【问题描述】:

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

【问题讨论】:

    标签: gradle rpm artifactory yum


    【解决方案1】:

    这里的问题是 Gradle 坚持以 maven 风格的目录格式 group-id/version/artifact 上传所有内容,而 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 publish attemps to upload RPM to Artifactory YUM repo 两次”stackoverflow.com/questions/40001668/… 使用这种方法
    • 这是一个糟糕的解决方案,很简单,因为它会在使用多个出版物时中断,或者像@popalka 一样,在上传多个工件时会中断。您应该使用真实的模式,而不是硬编码您期望的单个文件的名称。
    • 由于 Ivy 占位符 [originalname] 尚未在 Gradle 中实现,您应该使用另一个占位符(例如 [module])并将文件名放入该属性中。查看this minimal example
    【解决方案2】:

    这是我的代码 sn-ps 与 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).
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 2019-11-02
      • 1970-01-01
      相关资源
      最近更新 更多