Skip to content

Commit

Permalink
Merge pull request #54 from SwissBorg/use-diff-slick-version-for-scala3
Browse files Browse the repository at this point in the history
Use Slick 3.4.x for Scala 2 and Slick 3.5.x for Scala 3.
  • Loading branch information
tiagomota authored Sep 10, 2024
2 parents 139db1a + 056b060 commit 1d44ce6
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 50 deletions.
11 changes: 8 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ lazy val core = project
.enablePlugins(MimaPlugin)
.settings(
name := "pekko-persistence-postgres",
libraryDependencies ++= Dependencies.Libraries,
mimaBinaryIssueFilters ++= Seq()
mimaBinaryIssueFilters ++= Seq(),
libraryDependencies ++= {
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Dependencies.Libraries.scala3
case _ => Dependencies.Libraries.scala2
})
} ++ Dependencies.Libraries.testing
)

TaskKey[Unit]("verifyCodeFmt") := {
Expand All @@ -27,4 +32,4 @@ TaskKey[Unit]("verifyCodeFmt") := {
"Unformatted sbt code found. Please run 'scalafmtSbt' and commit the reformatted code"
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.apache.pekko.persistence.postgres.db

import com.github.tminglei.slickpg.*
import slick.basic.Capability
import slick.jdbc.JdbcCapabilities

trait ExtendedPostgresProfile
extends ExPostgresProfile
with PgArraySupport
with PgDate2Support
with PgRangeSupport
with PgHStoreSupport
with PgSearchSupport
with PgNetSupport
with PgJsonSupport
with PgLTreeSupport
with array.PgArrayJdbcTypes
with PgCirceJsonSupport {

def pgjson = "jsonb" // jsonb support is in postgres 9.4.0 onward; for 9.3.x use "json"

// Add back `capabilities.insertOrUpdate` to enable native `upsert` support; for postgres 9.5+
override protected def computeCapabilities: Set[Capability] =
super.computeCapabilities + JdbcCapabilities.insertOrUpdate

override val api: MyAPI.type = MyAPI

trait MyAPI
extends API
with ArrayImplicits
with SimpleArrayPlainImplicits
with DateTimeImplicits
with NetImplicits
with LTreeImplicits
with RangeImplicits
with HStoreImplicits
with SearchImplicits
with SearchAssistants
with JsonImplicits {
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
object MyAPI extends MyAPI
}

object ExtendedPostgresProfile extends ExtendedPostgresProfile
95 changes: 72 additions & 23 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,76 @@ object Dependencies {
val Scala3 = "3.3.3"
val ScalaVersions = Seq(Scala213, Scala3)

val PekkoVersion = "1.0.2"
val ScaffeineVersion = "5.3.0"
val ScalaTestVersion = "3.2.19"
val SlickVersion = "3.5.1"
val SlickPgVersion = "0.22.1"
val LogbackVersion = "1.5.8"
val PostgresqlVersion = "42.7.4"

val Libraries: Seq[ModuleID] = Seq(
"ch.qos.logback" % "logback-classic" % LogbackVersion % Test,
"com.github.blemale" %% "scaffeine" % ScaffeineVersion,
"com.github.tminglei" %% "slick-pg" % SlickPgVersion,
"com.github.tminglei" %% "slick-pg_circe-json" % SlickPgVersion,
"org.apache.pekko" %% "pekko-slf4j" % PekkoVersion % Test,
"org.apache.pekko" %% "pekko-persistence-tck" % PekkoVersion % Test,
"org.apache.pekko" %% "pekko-stream-testkit" % PekkoVersion % Test,
"org.apache.pekko" %% "pekko-testkit" % PekkoVersion % Test,
"org.apache.pekko" %% "pekko-persistence-query" % PekkoVersion % Provided,
"com.typesafe.slick" %% "slick" % SlickVersion,
"com.typesafe.slick" %% "slick-hikaricp" % SlickVersion,
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"org.postgresql" % "postgresql" % PostgresqlVersion % Test
)
object Libraries {
object Pekko {
private val Version = "1.0.1"

def slf4j = "org.apache.pekko" %% "pekko-slf4j" % Version
def persistence = "org.apache.pekko" %% "pekko-persistence-query" % Version
def persistenceTck = "org.apache.pekko" %% "pekko-persistence-tck" % Version
def testkit = "org.apache.pekko" %% "pekko-testkit" % Version
def streamTestkit = "org.apache.pekko" %% "pekko-stream-testkit" % Version
}

object Misc {
private val ScaffeineVersion = "5.3.0"
private val LogbackVersion = "1.5.8"
private val PostgresqlVersion = "42.7.4"
private val ScalaTestVersion = "3.2.19"

def scaffeine = "com.github.blemale" %% "scaffeine" % ScaffeineVersion
def logback = "ch.qos.logback" % "logback-classic" % LogbackVersion
def scalatest = "org.scalatest" %% "scalatest" % ScalaTestVersion
def postgresql = "org.postgresql" % "postgresql" % PostgresqlVersion
}

sealed trait Slick {
protected val SlickVersion: String
protected val SlickPgVersion: String

def slick = "com.typesafe.slick" %% "slick" % SlickVersion
def slickHikariCP = "com.typesafe.slick" %% "slick-hikaricp" % SlickVersion
def slickPg = "com.github.tminglei" %% "slick-pg" % SlickPgVersion
def slickPgCirce = "com.github.tminglei" %% "slick-pg_circe-json" % SlickPgVersion
}

object SlickForScala2 extends Slick {
override protected val SlickVersion = "3.4.1"
override protected val SlickPgVersion = "0.21.1"
}

object SlickForScala3 extends Slick {
override protected val SlickVersion = "3.5.1"
override protected val SlickPgVersion = "0.22.2"
}

private val common: Seq[ModuleID] = Seq(
Pekko.persistence % Provided,
Misc.scaffeine
)

val scala2: Seq[ModuleID] = common ++ Seq(
SlickForScala2.slick,
SlickForScala2.slickHikariCP,
SlickForScala2.slickPg,
SlickForScala2.slickPgCirce
)

val scala3: Seq[ModuleID] = common ++ Seq(
SlickForScala3.slick,
SlickForScala3.slickHikariCP,
SlickForScala3.slickPg,
SlickForScala3.slickPgCirce
)

val testing: Seq[ModuleID] = Seq(
Pekko.persistenceTck % Test,
Pekko.slf4j % Test,
Pekko.testkit % Test,
Pekko.streamTestkit % Test,
Misc.logback % Test,
Misc.postgresql % Test,
Misc.scalatest % Test
)
}
}
54 changes: 30 additions & 24 deletions project/ProjectAutoPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,10 @@ object ProjectAutoPlugin extends AutoPlugin {
)
)

override val projectSettings: Seq[Setting[_]] = Seq(
crossVersion := CrossVersion.binary,
crossScalaVersions := Dependencies.ScalaVersions,
scalaVersion := Dependencies.Scala213,
override val projectSettings: Seq[Setting[_]] = commonCrossCompileSettings ++ Seq(
Test / fork := true,
Test / parallelExecution := false,
Test / logBuffered := true,
scalacOptions ++= Seq(
"-encoding",
"UTF-8",
"-deprecation",
"-feature",
"-unchecked",
"-language:implicitConversions",
"-language:reflectiveCalls",
"-language:higherKinds",
"-release:11"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
List(
"-Xsource:3"
)
case Some((3, _)) =>
List("-source:3.0-migration")
case _ =>
Nil
}),
Compile / doc / scalacOptions := scalacOptions.value ++ Seq(
"-doc-title",
"Pekko Persistence Postgres",
Expand All @@ -71,4 +48,33 @@ object ProjectAutoPlugin extends AutoPlugin {
)
)

private lazy val commonScalacOptions: Seq[String] = Seq(
"-encoding",
"UTF-8", // Specify character encoding used by source files.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-language:implicitConversions",
"-language:reflectiveCalls",
"-language:higherKinds",
"-release:11"
)

private def commonCrossCompileSettings: Seq[Def.Setting[_]] = Seq(
scalaVersion := Dependencies.Scala3,
crossScalaVersions := Seq(Dependencies.Scala213, Dependencies.Scala3),
scalacOptions ++= {
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
commonScalacOptions ++ Seq(
// options dedicated for cross build / migration to Scala 3
"-source:3.0-migration"
)
case _ =>
commonScalacOptions ++ Seq(
"-Xsource:3"
)
})
}
)
}

0 comments on commit 1d44ce6

Please sign in to comment.