Sergey T.
Sergey T.

Reputation: 1

Create dynamic gradle publication

My gradle build produces different number of artifacts depending on the files being changed in GIT. So if for example file1.txt was changed it'll produce only file1.zip, if both file1.txt and file2.txt has been changed it'll produce 2 artifacts - file1.zip and file2.zip etc.

For each changed file I create new task dynamically:

def task = tasks.create(
        name: "zip:$component",
        type: Zip,
        overwrite: true) {
    from project.CONFIG_DIR
    include "$component/component.conf"
    baseName component
    destinationDir file("out")

now I want to publish the resulting out/*.zip artifacts to maven repository. Tried to do it with:

publishing.publications.add(task)

but got the following:

> org.gradle.api.tasks.bundling.Zip_Decorated cannot be cast to org.gradle.api.Named

Upvotes: 0

Views: 1629

Answers (1)

Vampire
Vampire

Reputation: 38669

publications.add would need a Publication object, not a Task object. What you are after is probably more

publishing {
   publications {
      myPublicationName(MavenPublication) {
         artifact task
      }
   }
}

or something like that.

Here you have the corresponding documentation where you can read more about it: https://docs.gradle.org/current/userguide/publishing_maven.html

Upvotes: 0

Related Questions