@@ -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