From ffbd6b9d50dffb77748b1e1d86005fe5a382e85e Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Mon, 10 Jul 2023 15:25:22 +0900 Subject: [PATCH] Scala 3 --- .github/workflows/build-test.yml | 2 +- build.sbt | 21 +++++++-- project/Dependencies.scala | 45 +++++++++++-------- .../api/db/slick/DatabaseConfigProvider.scala | 2 +- .../api/db/slick/DefaultSlickApiSpec.scala | 3 +- .../play/api/db/slick/SlickApiSpec.scala | 2 +- 6 files changed, 48 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 70092fe3..30ad55fa 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -38,7 +38,7 @@ jobs: uses: playframework/.github/.github/workflows/cmd.yml@v3 with: java: 17, 11 - scala: 2.13.x + scala: 2.13.x, 3.x cmd: sbt ++$MATRIX_SCALA test finish: diff --git a/build.sbt b/build.sbt index ba3bf3a9..5ac7488f 100644 --- a/build.sbt +++ b/build.sbt @@ -19,8 +19,15 @@ lazy val commonSettings = Seq( // Work around https://issues.scala-lang.org/browse/SI-9311 scalacOptions ~= (_.filterNot(_ == "-Xfatal-warnings")), scalaVersion := "2.13.11", // scala213, - crossScalaVersions := Seq("2.13.11"), // scala213, - pomExtra := scala.xml.NodeSeq.Empty, // Can be removed when dropping interplay + crossScalaVersions := Seq("2.13.11", "3.3.0"), // scala213, + scalacOptions ++= { + if (scalaBinaryVersion.value == "3") { + Seq("-source:3.0-migration") + } else { + Nil + } + }, + pomExtra := scala.xml.NodeSeq.Empty, // Can be removed when dropping interplay developers += Developer( "playframework", "The Play Framework Contributors", @@ -40,7 +47,7 @@ lazy val `play-slick-root` = (project in file(".")) lazy val `play-slick` = (project in file("src/core")) .enablePlugins(PlayLibrary, Playdoc, MimaPlugin) .configs(Docs) - .settings(libraryDependencies ++= Dependencies.core) + .settings(libraryDependencies ++= Dependencies.core.value) .settings(mimaSettings) .settings(commonSettings) @@ -68,5 +75,11 @@ val previousVersion: Option[String] = Some("5.0.2") ThisBuild / mimaFailOnNoPrevious := false def mimaSettings = Seq( - mimaPreviousArtifacts := previousVersion.map(organization.value %% moduleName.value % _).toSet + mimaPreviousArtifacts := { + if (scalaBinaryVersion.value == "3") { + Set.empty // TODO + } else { + previousVersion.map(organization.value %% moduleName.value % _).toSet + } + } ) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 7b01ebac..202f16a0 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,14 +1,17 @@ import sbt._ +import Keys._ object Dependencies { - val core = Seq( - Library.slick, - Library.slickHikariCP, - Library.playCore, - Library.playJdbcApi, - Library.playLogback % "test", - Library.playSpecs2 % "test", - Library.h2 % "test" + val core = Def.setting( + Seq( + Library.slick.value, + Library.slickHikariCP.value, + Library.playCore, + Library.playJdbcApi, + Library.playLogback % "test", + Library.playSpecs2 % "test", + Library.h2 % "test" + ) ) val evolutions = Seq( @@ -21,17 +24,23 @@ object Dependencies { object Version { val play = _root_.play.core.PlayVersion.current - val slick = "3.4.1" - val h2 = "2.1.214" + val slick = Def.setting( + if (scalaBinaryVersion.value == "3") { + "3.5.0-M4" + } else { + "3.4.1" + } + ) + val h2 = "2.1.214" } object Library { - val playLogback = "com.typesafe.play" %% "play-logback" % Version.play - val playCore = "com.typesafe.play" %% "play" % Version.play - val playJdbcApi = "com.typesafe.play" %% "play-jdbc-api" % Version.play - val playJdbcEvolutions = "com.typesafe.play" %% "play-jdbc-evolutions" % Version.play - val playSpecs2 = "com.typesafe.play" %% "play-specs2" % Version.play - val slick = "com.typesafe.slick" %% "slick" % Version.slick - val slickHikariCP = "com.typesafe.slick" %% "slick-hikaricp" % Version.slick - val h2 = "com.h2database" % "h2" % Version.h2 + val playLogback = "com.typesafe.play" %% "play-logback" % Version.play + val playCore = "com.typesafe.play" %% "play" % Version.play + val playJdbcApi = "com.typesafe.play" %% "play-jdbc-api" % Version.play + val playJdbcEvolutions = "com.typesafe.play" %% "play-jdbc-evolutions" % Version.play + val playSpecs2 = "com.typesafe.play" %% "play-specs2" % Version.play + val slick = Def.setting("com.typesafe.slick" %% "slick" % Version.slick.value) + val slickHikariCP = Def.setting("com.typesafe.slick" %% "slick-hikaricp" % Version.slick.value) + val h2 = "com.h2database" % "h2" % Version.h2 } diff --git a/src/core/src/main/scala/play/api/db/slick/DatabaseConfigProvider.scala b/src/core/src/main/scala/play/api/db/slick/DatabaseConfigProvider.scala index 87e3ea6d..4c2aeb7b 100644 --- a/src/core/src/main/scala/play/api/db/slick/DatabaseConfigProvider.scala +++ b/src/core/src/main/scala/play/api/db/slick/DatabaseConfigProvider.scala @@ -158,7 +158,7 @@ trait HasDatabaseConfig[P <: BasicProfile] { @deprecated("Use `profile` instead of `driver`", "2.1") protected final lazy val driver: P = dbConfig.profile // field is lazy to avoid early initializer problems. /** The Slick database extracted from `dbConfig`. */ - protected final def db: P#Backend#Database = dbConfig.db + protected final def db = dbConfig.db } /** diff --git a/src/core/src/test/scala/play/api/db/slick/DefaultSlickApiSpec.scala b/src/core/src/test/scala/play/api/db/slick/DefaultSlickApiSpec.scala index 40130932..55b836c6 100644 --- a/src/core/src/test/scala/play/api/db/slick/DefaultSlickApiSpec.scala +++ b/src/core/src/test/scala/play/api/db/slick/DefaultSlickApiSpec.scala @@ -2,7 +2,6 @@ package play.api.db.slick import java.util.concurrent.ConcurrentLinkedDeque -import org.specs2.mock.Mockito import org.specs2.mutable.Specification import play.api.inject.Injector import play.api.inject.ApplicationLifecycle @@ -10,7 +9,7 @@ import play.api.inject.DefaultApplicationLifecycle import play.api.inject.guice.GuiceApplicationBuilder import slick.basic.BasicProfile -class DefaultSlickApiSpec extends Specification with Mockito { self => +class DefaultSlickApiSpec extends Specification { self => sequential diff --git a/src/core/src/test/scala/play/api/db/slick/SlickApiSpec.scala b/src/core/src/test/scala/play/api/db/slick/SlickApiSpec.scala index f92ac1a8..1f23cb67 100644 --- a/src/core/src/test/scala/play/api/db/slick/SlickApiSpec.scala +++ b/src/core/src/test/scala/play/api/db/slick/SlickApiSpec.scala @@ -27,7 +27,7 @@ class SlickApiSpec extends Specification { "return a DatabaseConfig instance for a correctly configured database" in { import SUTWithGoodConfig._ val default = api.dbConfig[BasicProfile](DbName("default")) - default must not beNull + default must not(beNull) } "always return the same DatabaseConfig instance for a given database name" in { import SUTWithGoodConfig._