Skip to content

Commit

Permalink
Move servletSpec down to the base plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
earldouglas committed Oct 23, 2024
1 parent caa92bd commit 54371b0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
26 changes: 4 additions & 22 deletions src/main/scala/com/earldouglas/sbt/war/SbtWar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -33,6 +32,7 @@ object SbtWar extends AutoPlugin {
}

import autoImport._
import WebappComponentsPlugin.autoImport.servletSpec

override val requires: Plugins =
WarPackagePlugin
Expand Down Expand Up @@ -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]] =
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[_]] = {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 54371b0

Please sign in to comment.