[2.0.x] Fix duplicate autoplugins packageBin mappings (#9255) (#9273)

Deduplicate executable jar package entries. In the issue, the duplicate was something like:

(resource_managed/.../sbt/sbt.autoplugins, "sbt/sbt.autoplugins")
(classes/.../sbt/sbt.autoplugins,          "sbt/sbt.autoplugins")

This is because copyResources copied autoplugin metadata to the classes directory.

Solution: when composing the packageBinMappings, differentiate between artifacts that come from class directory and from outside of it. If there is a duplicate, prefer resource that comes from outside of it.

Co-authored-by: Anatolii Kmetiuk <[email protected]>
This commit is contained in:
eugene yokota
2026-05-30 20:16:58 -04:00
committed by GitHub
co-authored by Anatolii Kmetiuk
parent 8ff4a8ecba
commit e6666e4b10
4 changed files with 22 additions and 2 deletions
+10 -2
View File
@@ -1722,10 +1722,18 @@ object Defaults extends BuildCommon {
def packageBinMappings: Initialize[Task[Seq[(HashedVirtualFileRef, String)]]] =
Def.task {
val converter = fileConverter.value
val classDirPath = classDirectory.value.toPath.toAbsolutePath.normalize
val xs = products.value
xs
val allMappings = xs
.flatMap(Path.allSubpaths)
.withFilter(_._1.isFile())
.filter(_._1.isFile())
val resourcePaths = allMappings.collect {
case (p, path) if !p.toPath.toAbsolutePath.normalize.startsWith(classDirPath) => path
}.toSet
allMappings
.filterNot { (p, path) =>
resourcePaths(path) && p.toPath.toAbsolutePath.normalize.startsWith(classDirPath)
}
.map { (p, path) =>
val vf = converter.toVirtualFile(p.toPath())
(vf: HashedVirtualFileRef) -> path
@@ -0,0 +1,4 @@
ThisBuild / organization := "com.example"
ThisBuild / version := "0.1.0-SNAPSHOT"
val `scalac-options` = project.enablePlugins(SbtPlugin)
@@ -0,0 +1,5 @@
package example
import sbt.*
object ScalacOptionsPlugin extends AutoPlugin
@@ -0,0 +1,3 @@
> scalac-options / Compile / packageBin
> scalac-options / Compile / copyResources
> scalac-options / Compile / packageBin