2
votes

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

2 Answers

0
votes

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')
}
-1
votes

By default Gradle plugin maven-publish creates a conventional task per publication and repository, so if you define your publication then you can publish it using that conventional task.

For example if you have defined a z publication you can then use task publishZPublicationToMavenRepository.