Wednesday, July 3, 2019

Fixing the signing plugin on Gradle 5.1 and later

I previously found that using the maven-publish and signing Gradle plugins to publish to Maven Central did not work on Gradle versions 5.1 and newer: the signArchives task failed with a "duplicate key" error. So for a while I had to use the Gradle 5.0 wrapper to deploy. More recently I decided to investigate more thoroughly, and came up with a fix. Conveniently, the list of signatures is available from the signing task. Rather than this simple configuration block...
signing {
    sign configurations.archives
}

...I remove duplicates...
signing {
    def signTasks = sign configurations.archives
    signTasks.each { t ->
        def signatures = t.getSignatures()
        signatures.removeAll { oneSig ->
            signatures.count { anotherSig -> oneSig.getClassifier() == anotherSig.getClassifier() } > 1
        }
    }
}

...allowing the signing and upload to complete successfully.

No comments:

Post a Comment