Skip to content

Commit f5fd679

Browse files
authored
Merge pull request #280 from WojciechMazur/fix/export-jars
Workaround for `WebKeys.importDirectly` in sbt 2.x
2 parents 86bcf6f + a3fbc1a commit f5fd679

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: playframework/.github/.github/workflows/cmd.yml@v3
1919
with:
2020
java: 17, 11, 8
21-
scala: 2.12.20
21+
scala: 2.12.20, 3.7.2
2222
cmd: |
2323
sbt ++$MATRIX_SCALA test scripted
2424

build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ developers += Developer(
1111

1212
lazy val scala212 = "2.12.20"
1313
lazy val scala3 = "3.7.2"
14-
ThisBuild / crossScalaVersions := Seq(scala212)
15-
ThisBuild / scalaVersion := scala212
14+
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
1615

1716
libraryDependencies ++= Seq(
1817
"org.webjars" % "webjars-locator-core" % "0.59",

src/main/scala/com/typesafe/sbt/web/SbtWeb.scala

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ object SbtWeb extends AutoPlugin {
255255
Nil
256256
}
257257
},
258+
(Test / packageBin / packageOptions) ++= {
259+
if (exportJars.value) Some(Package.ManifestAttributes(ModuleNameAttribute -> moduleName.value))
260+
else None
261+
},
262+
(Compile / packageBin / packageOptions) ++= {
263+
if (exportJars.value) Some(Package.ManifestAttributes(ModuleNameAttribute -> moduleName.value))
264+
else None
265+
},
258266
(Compile / exportedProducts) ++= exportAssets(Assets, Compile, TrackLevel.TrackAlways).value,
259267
(Test / exportedProducts) ++= exportAssets(TestAssets, Test, TrackLevel.TrackAlways).value,
260268
(Compile / exportedProductsIfMissing) ++= exportAssets(Assets, Compile, TrackLevel.TrackIfMissing).value,
@@ -478,8 +486,27 @@ object SbtWeb extends AutoPlugin {
478486
* Get module names for all internal web module dependencies on the classpath.
479487
*/
480488
def getInternalWebModules(conf: Configuration): Def.Initialize[Task[Seq[String]]] = Def.task {
481-
(conf / internalDependencyClasspath).value.flatMap(_.get(toKey(WebKeys.webModulesLib)))
489+
implicit val fc: FileConverter = fileConverter.value
490+
(conf / internalDependencyClasspath).value
491+
.flatMap { entry =>
492+
// First, try attribute (sbt 1.x path when exportJars := false)
493+
entry
494+
.get(toKey(WebKeys.webModulesLib))
495+
.orElse {
496+
// Fallback for sbt 2.x where exportJars := true by default and the above attribute is missing.
497+
val file = toFile(entry.data)
498+
if (file.ext != "jar") None
499+
else
500+
io.Using.jarFile(verify = false)(file) { jar =>
501+
for {
502+
manifest <- Option(jar.getManifest())
503+
moduleName <- Option(manifest.getMainAttributes.getValue(ModuleNameAttribute))
504+
} yield moduleName
505+
}
506+
}
507+
}
482508
}
509+
private final val ModuleNameAttribute = "Sbt-Web-Module"
483510

484511
/**
485512
* Remove web module dependencies from a classpath. This is a helper method for Play 2.3 transitions.
@@ -585,7 +612,7 @@ object SbtWeb extends AutoPlugin {
585612
* Return the result of the first Some returning function.
586613
*/
587614
private def firstResult[A, B](fs: Seq[A => Option[B]])(a: A): Option[B] = {
588-
(fs.toStream flatMap { f => f(a).toSeq }).headOption
615+
fs.view.flatMap(_.apply(a).toSeq).headOption
589616
}
590617

591618
/**

0 commit comments

Comments
 (0)