我如何取消引用Gradle出版物的集合? [英] How do I de-reference a collection of Gradle publications?

查看:217
本文介绍了我如何取消引用Gradle出版物的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



单独发布Ivy出版物后,我如何才能在我的子项目部分中引用该集合?



我正在使用在嵌套迭代中构建rpms的任务 - 它们看起来有点像这样:

  def addWebServerTasks(aProject,hostId){
aProject.with {
taskbuildRpm _ $ {hostId}(type:Rpm,dependsOn:templates _ $ {hostId}){
...
}
publication.publications.create($ {project.name} - $ {hostId},IvyPublication){
工件任务。buildRpm _ $ {hostId }。outputs.getFiles()。getSingleFile()
}
}
}

这将创建8个RPMS,文件名格式为:subproject-env-region-hostname-version_branchname.rpm。以下是一个示例:

  web-server-config-DEV-EMEA-dev.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch。 rpm 
web-server-config-UAT-EMEA-uat.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-UAT-APAC-uat.server.com-1.1。 0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-PROD-APAC-prod1.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-PROD-APAC-prod2.server。 com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm

我已经声明一个存储库发布为如下,但它试图上传到的URL与RPM名称不匹配。

 子项目{
发布{
存储库{
ivy {
凭证{
用户名yumDeployUser
密码yumDeployPassword
}
url yumRepo
}
}




$ b $ p
$ b

对于每个RPM,我可以看到如下的输出,其中RPM文件名与文件系统上创建的名称不同 - 实际上,对于所有上述RPM,它都会尝试上传到相同的路径。

 :web-server-config:generateDescriptorFileForWeb-server-config-DEV-EMEA-dev.server.comPublication 
:web-server-config:publishWeb-server-config-DEV-EMEA-dev.server.comPublicationToIvyRepository
上传https://artifactrepository/artifactory/yum/foo/myproject/web-server-config/1.1.0 -feature_yum-upload-SNAPSHOT / web-server-config-1.1.0-feature_yum-upload-SNAPSHOT.rpm

缺少的是文件名的env-region-hostname部分。为什么会被丢弃?



注意:我试图从从Gradle上传RPM到Artifactory



解决方案:
根据Gradle文档,应该有一个[originalname]内置模式可用,但似乎没有实现。作为一种解决方法,重写然后使用[module]模式如下:

  def rpmFile = tasks。buildRpm _ $ {hostId }。outputs.getFiles()。getSingleFile()
publication.publications.create($ {project.name} - $ {hostId},IvyPublication){
artifact rpmFile
module rpmFile.getName()
}

然后您的发布部分应该如下所示:

 发布{
版本库{
ivy {
凭证{
username$ {citiEarUser}
密码$ {citiEarPassword}
}
url$ {yumRepo}
layout'pattern',{
artifact[module]





$ div class =h2_lin >解决方案

因为 [originalname] 占位符尚未实现,所以可以使用另一个占位符来提供e自定义模式的文件名:

  publishing {
publications {
myPub(IvyPublication){
神器myFile $ b $模块myFile.name
组织'myOrg'//需要某些未知原因
}
}
存储库{
常春藤{
url myUrl
layout'pattern',{
artifact'[module]'
}
}
}
}


SOLVED - see the end of this post.

When publishing Ivy publications individually, how can I then reference the collection in my subprojects section?

I'm working with tasks that build rpms inside a nested iteration - they look a bit like this:

def addWebServerTasks(aProject, hostId) {
    aProject.with {
        task "buildRpm_${hostId}"(type: Rpm, dependsOn: "templates_${hostId}") {
        ...
        }
        publishing.publications.create("${project.name}-${hostId}", IvyPublication) {
            artifact tasks."buildRpm_${hostId}".outputs.getFiles().getSingleFile()
        }
    }
}

This creates 8 RPMS with filenames in the format: subproject-env-region-hostname-version_branchname.rpm. Here's a sample:

web-server-config-DEV-EMEA-dev.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-UAT-EMEA-uat.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-UAT-APAC-uat.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-PROD-APAC-prod1.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-PROD-APAC-prod2.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm

I have declared a repository to publish to as below, but the URL it's trying to upload to does not match the RPM name.

subprojects {
    publishing {
        repositories {
            ivy {
                credentials {
                    username yumDeployUser
                    password yumDeployPassword
                }
                url yumRepo
            }
        }
    }
}

For each RPM, I can see output like the following, where the RPM file name is not the same as the one created on the filesystem - in fact, for all of the above RPMs, it tries to upload to the same path.

:web-server-config:generateDescriptorFileForWeb-server-config-DEV-EMEA-dev.server.comPublication
:web-server-config:publishWeb-server-config-DEV-EMEA-dev.server.comPublicationToIvyRepository
Upload https://artifactrepository/artifactory/yum/foo/myproject/web-server-config/1.1.0-feature_yum-upload-SNAPSHOT/web-server-config-1.1.0-feature_yum-upload-SNAPSHOT.rpm

What's missing is the "env-region-hostname" part of the filename. Why is this being dropped?

NOTE: I'm attempting to follow the publishing solution from (the accepted answer to) Upload an RPM to Artifactory from Gradle

SOLUTION: According to the Gradle documentation, there should be a [originalname] built-in pattern available, but it doesn't seem to be implemented. As a workaround, override and then use the [module] pattern as follows:

def rpmFile = tasks."buildRpm_${hostId}".outputs.getFiles().getSingleFile()
publishing.publications.create("${project.name}-${hostId}", IvyPublication) {
    artifact rpmFile
    module rpmFile.getName()
}

And then your publishing section should look like this:

publishing {
    repositories {
        ivy {
            credentials {
                username "${citiEarUser}"
                password "${citiEarPassword}"
            }
            url "${yumRepo}"
            layout 'pattern', {
                artifact "[module]"
            }
        }
    }
}

解决方案

Since, the [originalname] placeholder is not implemented yet, you could use another placeholder to provide the file name for your custom pattern:

publishing {
    publications {
        myPub(IvyPublication) {
            artifact myFile
            module myFile.name
            organisation 'myOrg' // required for some unknown reason
        }
    }
    repositories {
        ivy {
            url myUrl
            layout 'pattern', {
                artifact '[module]'
            }
        }
    }
}

这篇关于我如何取消引用Gradle出版物的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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