gpt4 book ai didi

gradle - 从复制任务发布工件

转载 作者:行者123 更新时间:2023-12-04 04:08:49 29 4
gpt4 key购买 nike

我的 gradle 构建副本文件。我想使用复制任务的输出作为 maven 工件发布的输入

例子 :

task example(type: Copy) {
from "build.gradle" // use as example
into "build/distributions"
}

publishing {
publications {
mavenJava(MavenPublication) {
artifact example
}
}
}

但 gradle 不喜欢它:
 * What went wrong:
A problem occurred configuring project ':myproject'.
> Exception thrown while executing model rule: PublishingPlugin.Rules#publishing(ExtensionContainer)
> Cannot convert the provided notation to an object of type MavenArtifact: task ':myproject:example'.
The following types/formats are supported:
- Instances of MavenArtifact.
- Instances of AbstractArchiveTask, for example jar.
- Instances of PublishArtifact
- Maps containing a 'source' entry, for example [source: '/path/to/file', extension: 'zip'].
- Anything that can be converted to a file, as per Project.file()

为什么 ?

据我了解,任务示例的输出应该由 Copy 任务设置。我假设它可以转换为某些文件。所以它应该用作发布任务的输入,作为文件。但是错误消息告诉我我错了。

我该如何解决?

谢谢

最佳答案

Gradle 不知道如何转换 Copy任务到 MavenArtifact , AbstractArchiveTask , PublishArtifact , .... 哪位解释一下错误信息。

但是 它确实知道如何转换 String作为 File ,正如在错误消息的最后一行中所解释的那样。

问题是如何强制 Gradle 在发布之前构建我的任务。 MavenArtifact有一个 builtBy方法就是在这里!

task example(type: Copy) {
from "build.gradle" // use as example
into "build/distributions"
}

publishing {
publications {
mavenJava(MavenPublication) {
// file to be transformed as an artifact
artifact("build/distributions/build.gradle") {
builtBy example // will call example task to build the above file
}
}
}
}

关于gradle - 从复制任务发布工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41044920/

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