From 38f54490843957c8ff29c947419034f612490ab2 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Tue, 16 Nov 2021 10:19:26 +0900 Subject: [PATCH] Update build settings for Scala 3 --- build.sbt | 25 +++++++++++++++++++------ project/Dependencies.scala | 24 +++++++++++++++++++++--- project/HouseRulesPlugin.scala | 5 +++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/build.sbt b/build.sbt index 72c80254b..e8c0a5d3b 100644 --- a/build.sbt +++ b/build.sbt @@ -102,8 +102,15 @@ def commonBaseSettings: Seq[Setting[_]] = Def.settings( run / fork := true, ) def commonSettings: Seq[Setting[_]] = - commonBaseSettings :+ - addCompilerPlugin(kindProjector) + commonBaseSettings :+ { + libraryDependencies ++= { + if (scalaBinaryVersion.value == "3") { + Nil + } else { + Seq(compilerPlugin(kindProjector)) + } + } + } def utilCommonSettings: Seq[Setting[_]] = baseSettings :+ (crossScalaVersions := (scala212 :: scala213 :: Nil)) @@ -463,7 +470,7 @@ lazy val utilScripted = (project in file("internal") / "util-scripted") .settings( utilCommonSettings, name := "Util Scripted", - libraryDependencies += scalaParsers, + libraryDependencies += scalaParsers.value, utilMimaSettings, ) .configure(addSbtIO) @@ -477,7 +484,7 @@ lazy val testingProj = (project in file("testing")) baseSettings, name := "Testing", libraryDependencies ++= Seq( - scalaXml, + scalaXml.value, testInterface, launcherInterface, sjsonNewScalaJson.value @@ -803,7 +810,13 @@ lazy val coreMacrosProj = (project in file("core-macros")) .settings( baseSettings :+ (crossScalaVersions := (scala212 :: scala213 :: Nil)), name := "Core Macros", - libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value, + libraryDependencies += { + if (scalaBinaryVersion.value == "3") { + "org.scala-lang" % "scala-compiler" % scala213 + } else { + "org.scala-lang" % "scala-compiler" % scalaVersion.value + } + }, SettingKey[Boolean]("exportPipelining") := false, mimaSettings, ) @@ -913,7 +926,7 @@ lazy val mainProj = (project in file("main")) } }, libraryDependencies ++= - (Seq(scalaXml, launcherInterface, caffeine, lmCoursierShaded) ++ log4jModules), + (Seq(scalaXml.value, launcherInterface, caffeine, lmCoursierShaded) ++ log4jModules), libraryDependencies ++= (scalaVersion.value match { case v if v.startsWith("2.12.") => List() case _ => List(scalaPar) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 42afc3136..aa9948bfc 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -100,9 +100,27 @@ object Dependencies { val scalaVerify = "com.eed3si9n.verify" %% "verify" % "1.0.0" val templateResolverApi = "org.scala-sbt" % "template-resolver" % "0.1" - val scalaXml = "org.scala-lang.modules" %% "scala-xml" % "1.3.0" - val scalaParsers = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2" - val scalaReflect = Def.setting("org.scala-lang" % "scala-reflect" % scalaVersion.value) + val scalaXml = Def.setting( + if (scalaBinaryVersion.value == "3") { + "org.scala-lang.modules" %% "scala-xml" % "2.0.1" + } else { + "org.scala-lang.modules" %% "scala-xml" % "1.3.0" + } + ) + val scalaParsers = Def.setting( + if (scalaBinaryVersion.value == "3") { + "org.scala-lang.modules" %% "scala-parser-combinators" % "2.1.0" + } else { + "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2" + } + ) + val scalaReflect = Def.setting( + if (scalaBinaryVersion.value == "3") { + "org.scala-lang" % "scala-reflect" % scala213 + } else { + "org.scala-lang" % "scala-reflect" % scalaVersion.value + } + ) val scalaPar = "org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.0" // specify all of log4j modules to prevent misalignment diff --git a/project/HouseRulesPlugin.scala b/project/HouseRulesPlugin.scala index 4a0b9fa1e..f1532dd8c 100644 --- a/project/HouseRulesPlugin.scala +++ b/project/HouseRulesPlugin.scala @@ -23,6 +23,7 @@ object HouseRulesPlugin extends AutoPlugin { }) .value .toList, + scalacOptions ++= "-Ykind-projector".ifScala3.value.toList, scalacOptions ++= "-Yinline-warnings".ifScala211OrMinus.value.toList, scalacOptions ++= "-Yno-adapted-args".ifScala212OrMinus.value.toList, scalacOptions += "-Ywarn-dead-code", @@ -44,5 +45,9 @@ object HouseRulesPlugin extends AutoPlugin { def ifScala211OrPlus = ifScalaGte(11) def ifScala212OrMinus = ifScalaLte(12) def ifScala213OrMinus = ifScalaLte(13) + def ifScala3 = Def.setting( + if (scalaBinaryVersion.value == "3") Seq(__x) + else Nil + ) } }