[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 <anatoliykmetyuk@gmail.com>
This commit is contained in:
eugene yokota 2026-05-30 20:16:58 -04:00 committed by GitHub
parent 8ff4a8ecba
commit e6666e4b10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 2 deletions

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

View File

@ -0,0 +1,4 @@
ThisBuild / organization := "com.example"
ThisBuild / version := "0.1.0-SNAPSHOT"
val `scalac-options` = project.enablePlugins(SbtPlugin)

View File

@ -0,0 +1,5 @@
package example
import sbt.*
object ScalacOptionsPlugin extends AutoPlugin

View File

@ -0,0 +1,3 @@
> scalac-options / Compile / packageBin
> scalac-options / Compile / copyResources
> scalac-options / Compile / packageBin