Using the maven-publish (or ivy-publish) plugin is it possible to restrict a publication to a subset of the defined repositories?
For example:
publishing {
publications {
main(MavenArtifact) {
artifact(file('main.txt'))
}
debug(MavenArtifact) {
artifact(file('debug.txt'))
}
}
repositories {
maven {
name = 'Main'
url = 'http://main.repository.com'
}
maven {
name = 'Debug'
url = 'http://debug.repository.com'
}
}
}
With this block, you would get 4 publish tasks (ignoring MavenLocal for the moment) * publishMainArtifactToMainRepository * publishMainArtifactToDebugRepository * publishDebugArtifactToMainRepository * publishDebugArtifactToDebugRepository
What I would like to configure is only the 1st and 4th tasks in the list above (i.e. restrict the Main artifact to only publish to the Main repository and Debug artifact to Debug repository).
How I was doing this was disabling the respective tasks:
afterEvaluate {
tasks.publishMainArtifactToDebugRepository.enabled = false
tasks.publishDebugArtifactToMainRepository.enabled = false
}
But after upgrading to Gradle 2.2.1, this stopped working. The TaskContainer was saying that these tasks did not exist at the time the afterEvaluate was executed. I got around this by switching to:
project.gradle.taskGraph.whenReady {
tasks.publishMainArtifactToDebugRepository.enabled = false
tasks.publishDebugArtifactToMainRepository.enabled = false
}
I am just wondering if there is a more elegant way to configure these types of restrictions since it would become unwieldily as more repositories or artifacts are added.