The “Conditional Signing” section of the User Guide uses the “required” flag of the SigningExtension, but this doesn’t seem to be a complete solution. SigningExtension will add the signature artifacts even if the signing task is not being run, because addSignaturesToConfiguration is always run. This method should internally be conditional on required or related to the actually running of a task.
The problem is that for the artifactory gradle plugin, I disable signing (because the users doing this don’t have signatories and we don’t need signatures for our local repo), via the required flag. This does skip the signArchives task, BUT the signatures are still in the configuration, so the artifactory plugin tries to publish them and they don’t exist. It doesn’t help that the working isn’t pretty:
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask("uploadMavenCentral")) {
signing {
required true
sign configurations.archives
}
}
}
I would have much preferred (and so would the User Guide):
signing {
required { project.taskGraph.hasTask("uploadMavenCentral") }
sign configurations.archives
}