Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing artifact from Copy task

Tags:

gradle

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

like image 702
dwursteisen Avatar asked Dec 08 '16 17:12

dwursteisen


People also ask

Is it possible to copy build artifact from pipeline into repo?

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.

How do you publish build artifacts on Azure DevOps?

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.


1 Answers

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
           }
        }
    }
}
like image 135
dwursteisen Avatar answered Nov 03 '22 06:11

dwursteisen