my gradle build copy files. I want to use the output of copy task as input for maven artifact publishing
example :
task example(type: Copy) {
from "build.gradle" // use as example
into "build/distributions"
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact example
}
}
}
but gradle doesn't like it :
* 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()
Why ?
As I understand, the outputs from the task example should be setted by the Copy task. I assume it can be converted to some files. So it should be used as input of the publishing task, as files. But the error message tell me I'm wrong.
How can I fix it ?
Thanks
Unfortunately, it is not possible to pass build artifacts from one Pipeline to another as it is only intended to work for steps. As a workaround, you can use the Downloads section of your repository to upload and get build artifacts.
See Artifacts in Azure Pipelines. Specify the name of the artifact that you want to create. It can be whatever you want. Choose whether to store the artifact in Azure Pipelines ( Container ), or to copy it to a file share ( FilePath ) that must be accessible from the build agent.
Gradle doesn't know how to convert a Copy
task to an MavenArtifact
, AbstractArchiveTask
, PublishArtifact
, .... Which explain the error message.
BUT it does know how to convert a String
as a File
, as it's explain in the last line of the error message.
The issue is how to force Gradle to build my task before publishing. MavenArtifact
has a builtBy
method which is here for that !
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
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With