3

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.

Nicolas Albert
  • 2,586
  • 1
  • 16
  • 16

2 Answers2

1

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')
}
k107
  • 15,882
  • 11
  • 61
  • 59
0

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.

webdizz
  • 828
  • 7
  • 10
  • But I want to exclude publishZPublicationToMavenRepository when I call "publish", "publishToMavenLocal", "publishToMavenRepository". – Nicolas Albert Jun 04 '17 at 07:02
  • Then you can just run `publish -X publushZPublicationToMavenRepository`. `-X` will exclude given task from execution plan. – webdizz Jun 04 '17 at 07:21
  • My team use the Eclipse gradle plugin, so the easy way is to double-click on a task without arguments. My current workaround is to disable publishZPublicationToMavenRepository by default and active it manualy when I need it. – Nicolas Albert Jun 06 '17 at 07:51
  • Well, there are some means Gradle offers OOTB check related documentation page out https://docs.gradle.org/current/userguide/more_about_tasks.html?_ga=2.92866522.65684940.1496735759-1476385789.1486043396#sec:skipping_tasks – webdizz Jun 06 '17 at 07:59