2

I was adapting a Gradle project from version 5.3 to version 7.3.3. Therefore the maven plugin had to be replaced with the maven-publish plugin.

Before, it was possible to skip long running tasks when deploying to the local .m2 repository/folder. All the gradle tasks which belonged to the skipped task were not executed. Note: The testJar serves just as an example. It's the bootJar task which is not needed all the time in the project I'm working on.

gradlew clean install -xtestJar --console=plain

However this seems not possible any more, because the artifact is hard coded within the publishing section of the maven-publish plugin.

gradlew clean publishToMavenLocal -xtestJar --console=plain

The following exception appears:

gradlew clean publishToMavenLocal -xtestJar --console=plain
> Task :clean
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jar
> Task :generateMetadataFileForMavenJavaPublication
> Task :generatePomFileForMavenJavaPublication
> Task :publishMavenJavaPublicationToMavenLocal FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishMavenJavaPublicationToMavenLocal'.
> Failed to publish publication 'mavenJava' to repository 'mavenLocal'
   > Invalid publication 'mavenJava': artifact file does not exist: 'C:\...\skippublish\build\libs\skippublish-0.0.1-SNAPSHOT-tests.jar'

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
5 actionable tasks: 5 executed

This is my minimal gradle project setup:

plugins {
    id "java-library"
    id "maven-publish"
}

group = "de.examplexyz"
sourceCompatibility = JavaVersion.VERSION_11

task testJar(type: Jar) {
    description = 'Assembles a JAR containing all test classes.'
    group = 'build'
    classifier = 'tests'
    from sourceSets.test.output
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact testJar
        }
    }
}

Is it possible to define or restrict the artifacts to publish (e.g. the testJar) by the gradle command, so the related tasks are not executed at all?

J.M.
  • 31
  • 2

0 Answers0