Skip to content

Commit

Permalink
Update built.sbt to support Scala 3 cross compile
Browse files Browse the repository at this point in the history
- Dropped support for Scala 2.12.x
- Fixed some sbt warnings caused by "in" syntax
- Replaced `versionDependent` helper with `CrossVersion`
- Updated some libraries to get Scala 3 versions
  • Loading branch information
JamieB-gu committed Jan 10, 2023
1 parent 8265fd8 commit d13e9d4
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
scalaVersion in ThisBuild := "2.13.10"
ThisBuild/scalaVersion := "3.2.1"

crossScalaVersions in ThisBuild := Seq(scalaVersion.value, "2.12.17")
ThisBuild/crossScalaVersions := Seq(scalaVersion.value, "2.13.10")

val commonSettings = Seq(
organization := "com.gu",
homepage := Some(url("https://github.com/guardian/marley")),
licenses := Seq("Apache V2" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")),
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"com.twitter" %% "scrooge-core" % "19.10.0",
"org.apache.thrift" % "libthrift" % "0.12.0"
)
("com.twitter" %% "scrooge-core" % "22.12.0").cross(CrossVersion.for3Use2_13),
"org.apache.thrift" % "libthrift" % "0.17.0"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",
)
case _ => Seq.empty
})
)

def versionDependent[T](scalaV: String, handlesAnnotations: Boolean, value: T):Option[T] = {
val preMacroAnnotationsScalaVersions = Set("2.11", "2.12")
Some(value).filter(_ => handlesAnnotations != preMacroAnnotationsScalaVersions.contains(scalaV))
}

lazy val core = project.settings(
name := "marley",
Compile / scalacOptions += versionDependent(scalaBinaryVersion.value, handlesAnnotations=true, "-Ymacro-annotations"),
libraryDependencies ++= versionDependent(scalaBinaryVersion.value, handlesAnnotations=false,
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)).toSeq ++ Seq(
Compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => Some("-Ymacro-annotations")
case _ => None
}),
libraryDependencies ++= Seq(
"org.apache.avro" % "avro" % "1.7.7",
"org.parboiled" %% "parboiled" % "2.1.8",
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",
"org.scalatest" %% "scalatest" % "3.0.9" % Test,
"org.scalacheck" %% "scalacheck" % "1.14.2" % Test
"org.parboiled" %% "parboiled" % "2.4.1",
"org.scalatest" %% "scalatest" % "3.2.15" % Test,
"org.scalacheck" %% "scalacheck" % "1.17.0" % Test
),
Test/testOptions += Tests.Argument(
TestFrameworks.ScalaTest,
Expand All @@ -37,10 +38,10 @@ lazy val core = project.settings(

lazy val thriftExample = project.settings(commonSettings: _*)

publishArtifact in Test := false
Test/publishArtifact := false

lazy val root = (project in file(".")).aggregate(core).settings(
aggregate in update := false,
update/aggregate := false,
publishArtifact := false,
publish := {},
publishLocal := {}
Expand Down

0 comments on commit d13e9d4

Please sign in to comment.