Gradle maven-publish : task to publish only one

Viewed 3211

I have a Java project that build and publish many jars (a.jar, b.jar, ...) using :

publishing {
    publications {
        a (MavenPublication) {
            artifactId 'a'
            artifact aJar
        }
        b (MavenPublication) {
            artifactId 'a'
            artifact aJar
        }
    }
}

repositories { ...

I have also define a z.jar and I want a special task to publish it and I want to not build / publish it for the build and publish (publishToMaven*) tasks.

How can I define this kind of task ?

I try something like that and other variant and it failed to compile the gradle :

task zPublish(type: PublishToMavenRepository) {
    publication = new MavenPublication() {
        artifactId 'z'
        artifact zJar
    }
}

I search in the source of maven-publish plugin without success.

Thanks for a good idea.

2 Answers

Try creating separate tasks

publishing {
    publications {
        a (MavenPublication) {
            artifactId 'a'
            artifact aJar
        }
        b (MavenPublication) {
            artifactId 'b'
            artifact bJar
        }
        z(MavenPublication) {
            artifact zJar
        }
    }
}

task zPublish() {
    dependsOn('publishZPublicationToMavenRepository')
    description('Publishes Z')
}

task otherPublish() {
    dependsOn('publishAPublicationToMavenRepository', 'publishBPublicationToMavenRepository')
    description('Publishes A and B')
}
Related