diff --git a/src/main/scala-2.12/PluginCompat.scala b/src/main/scala-2.12/PluginCompat.scala index f577c55f..d4476cce 100644 --- a/src/main/scala-2.12/PluginCompat.scala +++ b/src/main/scala-2.12/PluginCompat.scala @@ -10,6 +10,7 @@ import sbt.util.Tracked.{ inputChanged, lastOutput } import xsbti.FileConverter private[sbtassembly] object PluginCompat { + type Out = java.io.File type MainClass = sbt.Package.MainClass object CollectionConverters @@ -21,6 +22,8 @@ private[sbtassembly] object PluginCompat { a.data.toPath() def toFile(a: Attributed[File])(implicit conv: FileConverter): File = a.data + def toOutput(x: File)(implicit conv: FileConverter): File = + x def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] = cp.map(_.data.toPath()).toVector def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] = diff --git a/src/main/scala-3/PluginCompat.scala b/src/main/scala-3/PluginCompat.scala index b229bfb1..8027bc65 100644 --- a/src/main/scala-3/PluginCompat.scala +++ b/src/main/scala-3/PluginCompat.scala @@ -8,6 +8,7 @@ import sbt.librarymanagement.ModuleID import xsbti.{ FileConverter, HashedVirtualFileRef } object PluginCompat: + type Out = HashedVirtualFileRef type JarManifest = PackageOption.JarManifest type MainClass = PackageOption.MainClass type ManifestAttributes = PackageOption.ManifestAttributes @@ -23,6 +24,8 @@ object PluginCompat: conv.toPath(a.data) inline def toFile(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): File = toNioPath(a).toFile() + def toOutput(x: File)(implicit conv: FileConverter): HashedVirtualFileRef = + conv.toVirtualFile(x.toPath()) def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[NioPath] = cp.map(toNioPath).toVector inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[File] = @@ -56,7 +59,7 @@ object PluginCompat: ): CacheKey = 0 private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)( - buildAssembly: () => File - ): File = + buildAssembly: () => PluginCompat.Out + ): PluginCompat.Out = buildAssembly() end PluginCompat diff --git a/src/main/scala/sbtassembly/Assembly.scala b/src/main/scala/sbtassembly/Assembly.scala index 721c366c..a92820f9 100644 --- a/src/main/scala/sbtassembly/Assembly.scala +++ b/src/main/scala/sbtassembly/Assembly.scala @@ -170,7 +170,7 @@ object Assembly { val jarName: String = s"$name${if (version.nonEmpty) "-" else ""}$version.jar" } - def assemblyTask(key: TaskKey[File]): Initialize[Task[File]] = Def.task { + def assemblyTask(key: TaskKey[PluginCompat.Out]): Initialize[Task[PluginCompat.Out]] = Def.task { val t = (key / test).value val s = (key / streams).value val conv = fileConverter.value @@ -212,7 +212,7 @@ object Assembly { conv: FileConverter, cacheDir: File, log: Logger - ): File = { + ): PluginCompat.Out = { def timed[A](level: Level.Value, desc: String)(f: => A): A = { log.log(level, desc + " start:") val start = Instant.now().toEpochMilli @@ -322,7 +322,7 @@ object Assembly { if (mergeStrategy.name == MergeStrategy.rename.name) Option.empty else Option(mergeStrategy) } - val buildAssembly = () => { + val buildAssembly: () => PluginCompat.Out = () => { val mergedEntries = timed(Level.Debug, "Merge all conflicting jar entries (including those renamed)") { merge(renamedDependencies ++ others, secondPassMergeStrategy, log) } @@ -391,7 +391,7 @@ object Assembly { } log.info("Built: " + builtAssemblyJar.toPath) log.info("Jar hash: " + fullSha1) - builtAssemblyJar + toOutput(builtAssemblyJar) } val mergeStrategiesByPathList = timed(Level.Debug, "Collect all merge strategies for cache check") { // collect all diff --git a/src/main/scala/sbtassembly/AssemblyKeys.scala b/src/main/scala/sbtassembly/AssemblyKeys.scala index ca8f49d3..33969153 100644 --- a/src/main/scala/sbtassembly/AssemblyKeys.scala +++ b/src/main/scala/sbtassembly/AssemblyKeys.scala @@ -1,15 +1,15 @@ package sbtassembly import com.eed3si9n.jarjarabrams -import sbt.Keys._ -import sbt._ +import sbt.Keys.* +import sbt.* trait AssemblyKeys { - lazy val assembly = taskKey[File]("Builds a deployable über JAR") + lazy val assembly = taskKey[PluginCompat.Out]("Builds a deployable über JAR") lazy val assembleArtifact = settingKey[Boolean]("Enables (true) or disables (false) assembling an artifact") lazy val assemblyOption = taskKey[AssemblyOption]("Configuration for making a deployable über JAR") - lazy val assemblyPackageScala = taskKey[File]("Produces the Scala artifact") - lazy val assemblyPackageDependency = taskKey[File]("Produces the dependency artifact") + lazy val assemblyPackageScala = taskKey[PluginCompat.Out]("Produces the Scala artifact") + lazy val assemblyPackageDependency = taskKey[PluginCompat.Out]("Produces the dependency artifact") lazy val assemblyJarName = taskKey[String]("name of the über jar") lazy val assemblyDefaultJarName = taskKey[String]("default name of the über jar") lazy val assemblyOutputPath = taskKey[File]("output path of the über jar") diff --git a/src/main/scala/sbtassembly/AssemblyPlugin.scala b/src/main/scala/sbtassembly/AssemblyPlugin.scala index 01fa4af1..7abacc5d 100644 --- a/src/main/scala/sbtassembly/AssemblyPlugin.scala +++ b/src/main/scala/sbtassembly/AssemblyPlugin.scala @@ -108,6 +108,10 @@ object AssemblyPlugin extends sbt.AutoPlugin { def assemblyOptionSettings: Seq[Setting[_]] = Seq( assemblyOption := { val s = streams.value + val sr = assemblyShadeRules.value + if (sr.nonEmpty && exportJars.value) { + sys.error("exportJars must be set to false for the shading to work") + } AssemblyOption() .withIncludeBin((packageBin / assembleArtifact).value) .withIncludeScala((assemblyPackageScala / assembleArtifact).value) @@ -118,7 +122,7 @@ object AssemblyPlugin extends sbt.AutoPlugin { .withAppendContentHash(assemblyAppendContentHash.value) .withPrependShellScript(assemblyPrependShellScript.value) .withMaxHashLength(assemblyMaxHashLength.?.value) - .withShadeRules(assemblyShadeRules.value) + .withShadeRules(sr) .withScalaVersion(scalaVersion.value) .withLevel(logLevel.?.value.getOrElse(Level.Info)) .withRepeatableBuild(assemblyRepeatableBuild.value) diff --git a/src/sbt-test/merging/merging/build.sbt b/src/sbt-test/merging/merging/build.sbt index 28ec67b2..157e9423 100644 --- a/src/sbt-test/merging/merging/build.sbt +++ b/src/sbt-test/merging/merging/build.sbt @@ -1,6 +1,6 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" -ThisBuild / assemblyMergeStrategy := { +version := "0.1" +scalaVersion := "2.12.18" +assemblyMergeStrategy := { case "a" => MergeStrategy.concat case "b" => MergeStrategy.first case "c" => MergeStrategy.last @@ -9,9 +9,11 @@ ThisBuild / assemblyMergeStrategy := { case "f" => MergeStrategy.discard case PathList("x", "y") => MergeStrategy.discard case x => - val oldStrategy = (ThisBuild / assemblyMergeStrategy).value + val oldStrategy = assemblyMergeStrategy.value oldStrategy(x) } +name := "foo" +exportJars := true lazy val testmerge = (project in file(".")) .settings( @@ -25,9 +27,9 @@ lazy val testmerge = (project in file(".")) mustContain(dir / "d", Seq("1", "2", "3")) mustContain(dir / "e", Seq("1")) mustNotExist(dir / "f") - mustContain(dir / "README_foo", Seq("resources")) + mustContain(dir / "README_foo-0.1", Seq("resources")) mustContain(dir / "README_1", Seq("1")) - mustContain(dir / "LICENSE_foo", Seq("resources")) + mustContain(dir / "LICENSE_foo-0.1", Seq("resources")) mustContain(dir / "LICENSE" / "a", Seq("1")) // 80f5a06 -- don't rename License.class mustExist(dir / "com" / "example" / "License.class") diff --git a/src/sbt-test/merging/merging/test b/src/sbt-test/merging/merging/test index 8f0400c8..b7a2eeb6 100644 --- a/src/sbt-test/merging/merging/test +++ b/src/sbt-test/merging/merging/test @@ -1,4 +1,5 @@ # check if the file gets created +> debug > assembly # check if it says hello diff --git a/src/sbt-test/shading/directories/build.sbt b/src/sbt-test/shading/directories/build.sbt index 69bbc176..bb2b8d99 100644 --- a/src/sbt-test/shading/directories/build.sbt +++ b/src/sbt-test/shading/directories/build.sbt @@ -1,8 +1,8 @@ -ThisBuild / scalaVersion := "2.12.18" - -ThisBuild / assemblyShadeRules := Seq( +scalaVersion := "2.12.18" +assemblyShadeRules := Seq( ShadeRule.rename("somepackage.**" -> "shaded.@1").inAll ) +exportJars := false lazy val root = (project in file(".")) .settings( diff --git a/src/sbt-test/shading/jdk11/build.sbt b/src/sbt-test/shading/jdk11/build.sbt index 8ceeb03c..8734d587 100644 --- a/src/sbt-test/shading/jdk11/build.sbt +++ b/src/sbt-test/shading/jdk11/build.sbt @@ -1,3 +1,4 @@ +exportJars := false scalaVersion := scala212 lazy val scala212 = "2.12.18" diff --git a/src/sbt-test/shading/jdk17/build.sbt b/src/sbt-test/shading/jdk17/build.sbt index c9d696c4..118f0a5c 100644 --- a/src/sbt-test/shading/jdk17/build.sbt +++ b/src/sbt-test/shading/jdk17/build.sbt @@ -1,3 +1,4 @@ +exportJars := false scalaVersion := "2.13.12" assembly / assemblyShadeRules := Seq( diff --git a/src/sbt-test/shading/keeponly/build.sbt b/src/sbt-test/shading/keeponly/build.sbt index 9b727ad6..a64b7143 100644 --- a/src/sbt-test/shading/keeponly/build.sbt +++ b/src/sbt-test/shading/keeponly/build.sbt @@ -1,3 +1,4 @@ +exportJars := false lazy val scala212 = "2.12.18" lazy val scala213 = "2.13.11" @@ -16,7 +17,7 @@ lazy val testkeep = (project in file(".")). IO.unzip(crossTarget.value / "foo.jar", dir) mustNotExist(dir / "removed" / "ShadeClass.class") mustNotExist(dir / "removed" / "ShadePackage.class") - mustExist(dir / "keep" / "Keeped.class") + mustExist(dir / "keep" / "Kept.class") } }) diff --git a/src/sbt-test/shading/keeponly/src/main/scala/keep/Keeped.scala b/src/sbt-test/shading/keeponly/src/main/scala/keep/Kept.scala similarity index 53% rename from src/sbt-test/shading/keeponly/src/main/scala/keep/Keeped.scala rename to src/sbt-test/shading/keeponly/src/main/scala/keep/Kept.scala index 789b5f46..ee7c53ea 100644 --- a/src/sbt-test/shading/keeponly/src/main/scala/keep/Keeped.scala +++ b/src/sbt-test/shading/keeponly/src/main/scala/keep/Kept.scala @@ -1,3 +1,3 @@ package keep -class Keeped \ No newline at end of file +class Kept \ No newline at end of file diff --git a/src/sbt-test/shading/scalasigannot/build.sbt b/src/sbt-test/shading/scalasigannot/build.sbt index ddb335a7..a6444ba6 100644 --- a/src/sbt-test/shading/scalasigannot/build.sbt +++ b/src/sbt-test/shading/scalasigannot/build.sbt @@ -9,6 +9,7 @@ ThisBuild / crossScalaVersions := List(scala212, scala213) val shadingSettings: Seq[Def.Setting[_]] = Seq( + exportJars := false, assembly / assemblyShadeRules := Seq( ShadeRule.rename( "to.be.shaded.**" -> "shade.@1" @@ -18,7 +19,7 @@ val shadingSettings: Seq[Def.Setting[_]] = Seq( assembly / assemblyExcludedJars := { val cp = (assembly / fullClasspath).value cp.filterNot {p => - p.data.getName.startsWith("tobeshaded") + p.data.toString.contains("tobeshaded") } }, @@ -39,10 +40,10 @@ lazy val fatLib = project.in(file("fatlib")) Seq( name := "fatlib", (Compile / unmanagedJars) := { - val tbs: File = (toBeShaded / Compile / packageBin).value + val tbs = (toBeShaded / Compile / packageBin).value //Seq(sbt.internal.util.Attributed.blank[java.io.File](tbs)) - Seq(Attributed.blank[java.io.File](tbs)) + Seq(Attributed.blank(tbs)) } ) ) @@ -62,8 +63,9 @@ lazy val root = project.in(file(".")) //Seq(sbt.internal.util.Attributed.blank[java.io.File](tbs)) val x = (fatLib / Compile / assembly).value - Seq(Attributed.blank[java.io.File](x)) - } + Seq(Attributed.blank(x)) + }, + fgRun / aggregate := false, ) ) .aggregate(fatLib, toBeShaded) \ No newline at end of file diff --git a/src/sbt-test/shading/scalasigannot/project/plugins.sbt b/src/sbt-test/shading/scalasigannot/project/plugins.sbt index 25c3fb81..b7bb6c0d 100644 --- a/src/sbt-test/shading/scalasigannot/project/plugins.sbt +++ b/src/sbt-test/shading/scalasigannot/project/plugins.sbt @@ -3,5 +3,5 @@ if(pluginVersion == null) throw new RuntimeException("""|The system property 'plugin.version' is not defined. |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) - else addSbtPlugin("com.eed3si9n" % "sbt-assembly" % pluginVersion changing()) + else addSbtPlugin("com.eed3si9n" % "sbt-assembly" % pluginVersion) } diff --git a/src/sbt-test/shading/scalasigannot/test b/src/sbt-test/shading/scalasigannot/test index 06b8f1c0..7999a1f1 100644 --- a/src/sbt-test/shading/scalasigannot/test +++ b/src/sbt-test/shading/scalasigannot/test @@ -1,3 +1,3 @@ # Run the main project -> +root/run +> +root/fgRun diff --git a/src/sbt-test/shading/shading/build.sbt b/src/sbt-test/shading/shading/build.sbt index d6038ad6..e9a54fb3 100644 --- a/src/sbt-test/shading/shading/build.sbt +++ b/src/sbt-test/shading/shading/build.sbt @@ -1,3 +1,5 @@ +exportJars := false + lazy val testshade = (project in file(".")). settings( version := "0.1", diff --git a/src/sbt-test/shading/unmanagedjars/build.sbt b/src/sbt-test/shading/unmanagedjars/build.sbt index 59b3d811..5b5f237a 100644 --- a/src/sbt-test/shading/unmanagedjars/build.sbt +++ b/src/sbt-test/shading/unmanagedjars/build.sbt @@ -1,3 +1,5 @@ +exportJars := false + lazy val testshade = (project in file(".")). settings( version := "0.1",