diff --git a/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala b/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala index 2b688668..aff2a484 100644 --- a/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala +++ b/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala @@ -22,7 +22,6 @@ object SbtWar extends AutoPlugin { object autoImport { lazy val War = config("war").hide - lazy val servletSpec = settingKey[String]("servlet spec version") lazy val warPort = settingKey[Int]("container port") lazy val warStart = taskKey[Unit]("start container") lazy val warJoin = taskKey[Unit]("join container") @@ -33,6 +32,7 @@ object SbtWar extends AutoPlugin { } import autoImport._ + import WebappComponentsPlugin.autoImport.servletSpec override val requires: Plugins = WarPackagePlugin @@ -115,28 +115,11 @@ object SbtWar extends AutoPlugin { .withOutputStrategy(Some(BufferedOutput(streams.value.log))) } - val runnerLibraries: Initialize[Seq[ModuleID]] = + val runnerLibrary: Initialize[ModuleID] = Def.setting { - - val servletApi: ModuleID = - servletSpec.value match { - case "3.0" => - "javax.servlet" % "javax.servlet-api" % "3.0.1" - case "3.1" => - "javax.servlet" % "javax.servlet-api" % "3.1.0" - case "4.0" => - "jakarta.servlet" % "jakarta.servlet-api" % "4.0.4" - case "6.0" => - "jakarta.servlet" % "jakarta.servlet-api" % "6.0.0" - } - val warRunnerVersion: String = s"${servletSpec.value}_${BuildInfo.version}" - - Seq( - "com.earldouglas" % s"war-runner" % warRunnerVersion % War, - servletApi % Provided - ) + "com.earldouglas" % s"war-runner" % warRunnerVersion % War } val quickstartWar: Initialize[Task[Unit]] = @@ -188,8 +171,7 @@ object SbtWar extends AutoPlugin { Seq( Global / onLoad := onLoadSetting.value, - libraryDependencies ++= runnerLibraries.value, - servletSpec := "6.0", + libraryDependencies += runnerLibrary.value, warForkOptions := forkOptions.value, warJoin := joinWar.value, warPort := 8080, diff --git a/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala b/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala index a2a493bc..49f941c2 100644 --- a/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala +++ b/src/main/scala/com/earldouglas/sbt/war/WarPackagePlugin.scala @@ -16,7 +16,8 @@ import sbt._ */ object WarPackagePlugin extends AutoPlugin { - override def requires = WebappComponentsPlugin + override val requires: Plugins = + WebappComponentsPlugin override lazy val projectSettings: Seq[Setting[_]] = { diff --git a/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala b/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala index fd8bd327..e828f903 100644 --- a/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala +++ b/src/main/scala/com/earldouglas/sbt/war/WebappComponentsPlugin.scala @@ -28,6 +28,9 @@ object WebappComponentsPlugin extends AutoPlugin { object autoImport { + lazy val servletSpec: SettingKey[String] = + settingKey[String]("servlet spec version") + lazy val warResources: TaskKey[Map[String, File]] = taskKey[Map[String, File]]("webapp resources") @@ -51,6 +54,23 @@ object WebappComponentsPlugin extends AutoPlugin { override val projectSettings: Seq[Setting[_]] = { + val servletApi: Initialize[ModuleID] = + Def.setting { + val servletApi: ModuleID = + servletSpec.value match { + case "3.0" => + "javax.servlet" % "javax.servlet-api" % "3.0.1" + case "3.1" => + "javax.servlet" % "javax.servlet-api" % "3.1.0" + case "4.0" => + "jakarta.servlet" % "jakarta.servlet-api" % "4.0.4" + case "6.0" => + "jakarta.servlet" % "jakarta.servlet-api" % "6.0.0" + } + + servletApi % Provided + } + val warResourcesTask: Initialize[Task[Map[String, File]]] = (Compile / sourceDirectory) .map(_ / "webapp") @@ -67,6 +87,8 @@ object WebappComponentsPlugin extends AutoPlugin { .map(WebappComponents.getLib) Seq( + servletSpec := "6.0", + libraryDependencies += servletApi.value, warResources := warResourcesTask.value, warClasses := warClassesTask.value, warLib := warLibTask.value