[2.x] fix: Skip checksum generation for asc file, take 2 (#9499)

**Problem**
Checksums are still generated for asc file.
1. localStaging is a file repo, which was not handled
2. It was checking Artifact name, not the file name

**Solution**
This fixes both.
This commit is contained in:
eugene yokota 2026-07-24 16:42:04 -04:00 committed by GitHub
parent 0a0d6f67df
commit a0c4773a73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 18 deletions

View File

@ -116,18 +116,13 @@ private[sbt] object ConvertResolver {
checksum <- checksums
if !ChecksumHelper.isKnownAlgorithm(checksum)
} throw new IllegalArgumentException("Unknown checksum algorithm: " + checksum)
repository.put(artifact, src, dest, overwrite);
// Fix for sbt#1156 - Artifactory will auto-generate MD5/sha1 files, so
// we need to overwrite what it has.
if (!artifact.getName.endsWith(".asc")) {
for (checksum <- checksums) {
putChecksumMethod match {
repository.put(artifact, src, dest, overwrite)
if !dest.endsWith(".asc") then
for checksum <- checksums do
putChecksumMethod match
case Some(method) =>
method.invoke(this, artifact, src, dest, true: java.lang.Boolean, checksum)
case None => // TODO - issue warning?
}
}
}
if (signerName != null) {
putSignatureMethod match {
case None => ()
@ -219,15 +214,16 @@ private[sbt] object ConvertResolver {
resolver
}
case repo: FileRepository => {
val resolver = new FileSystemResolver with DescriptorRequired {
// Workaround for #1156
// Temporarily in sbt 0.13.x we deprecate overwriting
// in local files for non-changing revisions.
// This will be fully enforced in sbt 1.0.
setRepository(new WarnOnOverwriteFileRepo())
override val managedChecksumsEnabled: Boolean = managedChecksums
override def getResource(resource: Resource, dest: File): Long = get(resource, dest)
}
val resolver =
new FileSystemResolver with ChecksumFriendlyURLResolver with DescriptorRequired {
// Workaround for #1156
// Temporarily in sbt 0.13.x we deprecate overwriting
// in local files for non-changing revisions.
// This will be fully enforced in sbt 1.0.
setRepository(new WarnOnOverwriteFileRepo())
override val managedChecksumsEnabled: Boolean = managedChecksums
override def getResource(resource: Resource, dest: File): Long = get(resource, dest)
}
resolver.setName(repo.name)
initializePatterns(resolver, repo.patterns, settings)
import repo.configuration.{ isLocal, isTransactional }

View File

@ -0,0 +1,25 @@
// `signTask` stands in for sbt-pgp's signing task: it just writes a fake signature file
// and publishes it as an extra artifact with an ".asc" extension.
useIvy := true
organization := "com.example"
name := "foo"
version := "1.0.0"
scalaVersion := "2.12.21"
autoScalaLibrary := false
crossPaths := false
Compile / packageDoc / publishArtifact := false
Compile / packageSrc / publishArtifact := false
publishTo := localStaging.value
lazy val signTask = taskKey[HashedVirtualFileRef]("Emulates sbt-pgp's signing task")
signTask := {
val conv = fileConverter.value
val out = target.value / "foo-1.0.0.jar.asc"
IO.write(out, "fake-signature")
conv.toVirtualFile(out.toPath)
}
addArtifact(Artifact("foo", "asc", "jar.asc"), signTask)

View File

@ -0,0 +1,5 @@
libraryDependencies += Defaults.sbtPluginExtra(
"org.scala-sbt" % "sbt-ivy" % sbtVersion.value,
sbtVersion.value,
scalaVersion.value,
)

View File

@ -0,0 +1,16 @@
# useIvy := true forces the Ivy-backed publisher (ConvertResolver), which is what generates
# checksums via the ChecksumFriendlyURLResolver shim.
> publish
# ordinary artifacts and their checksums are published as usual
$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.jar
$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.jar.md5
$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.jar.sha1
$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.pom
$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.pom.md5
$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.pom.sha1
# the .asc signature artifact is published, but must NOT get its own checksum files
$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.jar.asc
-$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.jar.asc.md5
-$ exists target/sona-staging/com/example/foo/1.0.0/foo-1.0.0.jar.asc.sha1