gpt4 book ai didi

gradle - 如何在自定义PublishToIvyRepository任务中重用IvyPublication?

转载 作者:行者123 更新时间:2023-12-03 04:50:59 24 4
gpt4 key购买 nike

我有一个build.gradle文件,该文件带有要发布的 Artifact ,并遵循Ivy publishing documentation中给出的准则。

publishing {
publications {
ivy(IvyPublication) {
from components.java
descriptor.withXml {
asNode().info[0].appendNode("description", description)
}
}
}
}

我有一个单独的 PublishToIvyRepository 任务,我想对其进行配置,以使其转到正常的其他存储库,但使用与上述代码相同的发布。我最初的尝试是这样的:
task publishToIvyLocal(type: PublishToIvyRepository) {
repository = mySpecialRepository
publication = project.publishing.publications[0]
}

但是,这似乎不起作用。如果将其放在上面的 publishing {}块之前,则会出现以下错误:

Cannot configure the 'publishing' extension after it has been accessed.



我猜 project.publishing.publications[0]并不是重用此出版物的最佳方法。

如何在自定义PublishToIvyRepository任务中重用IvyPublication?

最佳答案

无需自己创建PublishToIvyRepository任务。

Applying the 'ivy-publish' plugin does the following:

  • [...]
  • Establishes a rule to automatically create a PublishToIvyRepository task for the combination of each IvyPublication added (see Section 35.2, “Publications”), with each IvyArtifactRepository added (see Section 35.3, “Repositories”).

因此,只需将您的发布与两个存储库一起添加,就会创建两个任务,一个任务是为每个存储库发布发布。

The created task is named publish«PUBNAME»PublicationTo«REPONAME»Repository, which is publishIvyJavaPublicationToIvyRepository for this example.


一些示例代码:
publishing {
publications {
mySpecial(IvyPublication) {
// configure publication
}
}
repositories {
ivy {
name = 'first'
// configure first repository
}
ivy {
name = 'second'
// configure second repository
}
}
}
这应该创建以下任务:
  • publishMySpecialPublicationToFirstRepository
  • publishMySpecialPublicationToSecondRepository

  • 关于存储库名称:

    The name for this repository. A name must be unique amongst a repository set. A default name is provided for the repository if none is provided.

    关于gradle - 如何在自定义PublishToIvyRepository任务中重用IvyPublication?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48410071/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com