Disable maven-publish related tasks not possible?


(jbaranski) #1

Is there a way to disable the maven-publish plugin under certain circumstances?

// This works fine
project.tasks.publish.enabled = false

generatePomFileForMavenPublication and publishMavenPublicationToMavenRepository still run. I want to disable these tasks as well.

// This results in error
project.tasks.generatePomFileForMavenPublication.enabled = false
project.tasks.publishMavenPublicationToMavenRepository.enabled = false

The error message is:

Could not find property ‘generatePomFileForMavenPublication’ on task set.

I feel like I’m missing something basic here…


(Benjamin Muschko) #2

I’d probably move the publishing code into a script plugin and then determine if it’s need by your “circumstance”.

if(today == 'Monday') {
    apply from: 'publishing.gradle'
}

The reason the task generatePomFileForMavenPublication is not accessible yet is because the plugin delays the creation of the task. You can probably make it work as such:

project.afterEvaluate {
    project.tasks.generatePomFileForMavenPublication.enabled = false
    project.tasks.publishMavenPublicationToMavenRepository.enabled = false
}

(jbaranski) #3

I’m already doing your first point at a different level in my build and everywhere I call “publish” I don’t want to add a condition that says if “my task exists” then “publish” so I’m just trying to disable the tasks.

Your afterEvaluate suggestion did not work, and after looking at the gradle source code I can’t find generatePomFileForMavenPublication and publishMavenPublicationToMavenRepository tasks anywhere so I don’t know where they are coming from.

Can you point me in the right direction to where in the gradle source those two tasks are being created?


(jbaranski) #4

Here is a working solution…

subprojects {
    apply plugin: "maven-publish"
    publishing {...}
    model {
        tasks.generatePomFileForMavenPublication {
            enabled = false
        }
        tasks.publishMavenPublicationToMavenRepository {
            enabled = false
        }
    }
    tasks.publish.enabled = false
}

(will) #5

I’m using gradel 4.4.1 – That last suggestion doesn’t work for me. Since my local maven repository is on my hard-drive, dropping the directory is actually more expedient.

In my case I want to prevent publication of any artefact form the IntegrationTesting project. The obvious answer didn’t work, viz:

publishToMavenLocal.onlyIf {  false  }

In the sub-project’s build.gradle file. While the task output say, “SKIPPED” but the IntegrationTest folder and contents still appear in the repository.

WHY are these tasks immune to the onlyif construct anyway!???

many thanks,
Will