79762141

Date: 2025-09-11 15:53:26
Score: 1
Natty:
Report link

Thanks to onlyIf hint from @Cisco I managed to create this helper method which now lives inside my convention plugins:

fun allExistingArtifactChecksumsInRepositoryMatch(
    repository: MavenArtifactRepository,
    publication: MavenPublication,
): Boolean {
    //...
    return when (val repositoryScheme = repositoryURI.scheme) {
        "http", "https" -> {
            // Create the HttpClient and use it to fetch existing checksums
        }
        "file" -> {
            // Use Path objects to do the same thing
        }
        else -> {
            // Maybe add support later, if necessary
            println("Unsupported repository scheme $repositoryScheme")
            false
        }
    }
}

After fetching the existing checksums, compute checksums of new artifacts using DigestOutputStream and compare them.

A somewhat important detail seems to be to do this:

val artifactsToCheck = when (publication) {
    is MavenPublicationInternal -> publication.asNormalisedPublication().allArtifacts
    else -> publication.artifacts
}

This downcast to internal gradle API seems to be necessary to also check metadata artifacts. This is valid for gradle version 8.13.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Cisco
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Quinteger