Skip to content

Commit

Permalink
Cross-build to Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jan 11, 2021
1 parent b870814 commit 645d087
Show file tree
Hide file tree
Showing 59 changed files with 1,392 additions and 798 deletions.
9 changes: 0 additions & 9 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ updates.pin = [
// https://github.com/akka/akka/blob/master/project/Dependencies.scala#L24
{ groupId = "com.fasterxml.jackson.core", version = "2.10." }
{ groupId = "com.fasterxml.jackson.datatype", version = "2.10." }
// "It is not forward binary compatible with 1.0.x: libraries compiled with 1.1.0 cannot be used with 1.0.x."
// https://users.scala-lang.org/t/announcing-scala-js-1-1-0/6053/3?u=sjrd
{ groupId = "org.scala-js", artifactId = "sbt-scalajs", version = "1.0." }
{ groupId = "org.scala-js", artifactId = "scalajs-compiler", version = "1.0." }
{ groupId = "org.scala-js", artifactId = "scalajs-library", version = "1.0." }
{ groupId = "org.scala-js", artifactId = "scalajs-test-bridge", version = "1.0." }
// Scalatest 3.2.x pulls in ScalaJs 1.1
{ groupId = "org.scalatest", artifactId = "scalatest", version = "3.1." }
{ groupId = "org.scalatestplus", artifactId = "scalacheck-1-14", version = "3.1." }
]

commits.message = "${artifactName} ${nextVersion} (was ${currentVersion})"
5 changes: 3 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ assumeStandardLibraryStripMargin = true
danglingParentheses = true
docstrings = JavaDoc
maxColumn = 120
project.excludeFilters += core/play/src/main/scala/play/core/hidden/ObjectMappings.scala
#scalafmt does not support Scala 3 syntax yet (`inline`)
project.excludeFilters += scala-3
project.git = true
rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifiers, PreferCurlyFors ]
rewrite.neverInfix.excludeFilters = [
Expand All @@ -19,4 +20,4 @@ version = 2.3.2

literals.long=Upper
literals.float=Upper
literals.double=Upper
literals.double=Upper
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ jobs:
- SCALA_VERSION=2.13.4
- TRAVIS_JDK=8

- name: "Run tests with Scala 3 and AdoptOpenJDK 8"
script: scripts/test-code.sh
env:
- SCALA_VERSION=3.0.0-M3
- TRAVIS_JDK=8

- stage: publish
name: "Publish artifacts to Bintray"
script: sbt +publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Employee {
"lastName" -> e.lastName,
"city" -> e.city,
"country" -> e.country,
"tags" -> JsArray(e.tags.map(JsString.apply))
"tags" -> JsArray(e.tags.map(JsString.apply _))
)
}

Expand Down
76 changes: 51 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import sbtcrossproject.CrossType

resolvers ++= DefaultOptions.resolvers(snapshot = true)

val specs2 = Seq(
"org.specs2" %% "specs2-core" % "4.10.5" % Test,
"org.specs2" %% "specs2-junit" % "4.10.5" % Test,
)
def specs2(scalaVersion: String) =
Seq(
"org.specs2" %% "specs2-core" % "4.10.5" % Test,
"org.specs2" %% "specs2-junit" % "4.10.5" % Test,
).map(_.withDottyCompat(scalaVersion))

val jacksonDatabindVersion = "2.10.5.1"
val jacksonDatabind = Seq(
Expand All @@ -34,7 +35,7 @@ val joda = Seq(
"joda-time" % "joda-time" % "2.10.8"
)

def jsonDependencies(scalaVersion: String) = Seq(
def scalaReflect(scalaVersion: String) = Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion
)

Expand All @@ -43,6 +44,7 @@ def jsonDependencies(scalaVersion: String) = Seq(
// Do not check for previous JS artifacts for upgrade to Scala.js 1.0 because no sjs1 artifacts exist
def playJsonMimaSettings = Seq(
mimaPreviousArtifacts := ((crossProjectPlatform.?.value, previousStableVersion.value) match {
case _ if isDotty.value => Set.empty // no releases for Scala 3 yet
case (Some(JSPlatform), Some("2.8.1")) => Set.empty
case (_, Some(previousVersion)) => Set(organization.value %%% moduleName.value % previousVersion)
case _ => throw new Error("Unable to determine previous version")
Expand All @@ -64,6 +66,7 @@ val javacSettings = Seq(
)

val scalacOpts = Seq(
"-language:higherKinds",
"-target:jvm-1.8",
"-Ywarn-unused:imports",
"-Xlint:nullary-unit",
Expand All @@ -74,10 +77,14 @@ val scalacOpts = Seq(

val silencerVersion = "1.7.1"

libraryDependencies in ThisBuild ++= Seq(
compilerPlugin(("com.github.ghik" % "silencer-plugin" % silencerVersion).cross(CrossVersion.full)),
("com.github.ghik" % "silencer-lib" % silencerVersion % Provided).cross(CrossVersion.full)
)
libraryDependencies in ThisBuild ++= {
if (isDotty.value) Nil
else
Seq(
compilerPlugin(("com.github.ghik" % "silencer-plugin" % silencerVersion).cross(CrossVersion.full)),
("com.github.ghik" % "silencer-lib" % silencerVersion % Provided).cross(CrossVersion.full)
)
}

// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
dynverVTagPrefix in ThisBuild := false
Expand All @@ -104,12 +111,12 @@ lazy val commonSettings = Def.settings(
Tests.Argument(TestFrameworks.ScalaTest, "-l", "play.api.libs.json.UnstableInScala213")
),
headerLicense := Some(HeaderLicense.Custom(s"Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>")),
scalaVersion := Dependencies.Scala212,
crossScalaVersions := Seq(Dependencies.Scala212, Dependencies.Scala213),
scalaVersion := Dependencies.Scala3, // 212,
crossScalaVersions := Seq(Dependencies.Scala212, Dependencies.Scala213, Dependencies.Scala3),
javacOptions in Compile ++= javacSettings,
javacOptions in Test ++= javacSettings,
javacOptions in (Compile, compile) ++= Seq("-target", "1.8"), // sbt #1785, avoids passing to javadoc
scalacOptions ++= scalacOpts,
scalacOptions ++= (if (isDotty.value) Nil else scalacOpts),
scalacOptions in (Compile, doc) ++= Seq(
// Work around 2.12 bug which prevents javadoc in nested java classes from compiling.
"-no-java-comments",
Expand All @@ -136,28 +143,46 @@ lazy val `play-json` = crossProject(JVMPlatform, JSPlatform)
.enablePlugins(Omnidoc, Publish, Playdoc)
.configs(Docs)
.settings(
commonSettings ++ playJsonMimaSettings ++ Seq(
libraryDependencies ++= jsonDependencies(scalaVersion.value) ++ Seq(
"org.scalatest" %%% "scalatest" % "3.1.2" % Test, // 3.1.2 is the last version that uses Scala.js 1.0.x
"org.scalatestplus" %%% "scalacheck-1-14" % "3.1.2.0" % Test,
"org.scalacheck" %%% "scalacheck" % "1.14.3" % Test,
"com.chuusai" %% "shapeless" % "2.3.3" % Test,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
),
commonSettings ++ playJsonMimaSettings ++ Def.settings(
libraryDependencies ++= (if (isDotty.value) Nil else scalaReflect(scalaVersion.value)),
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % "3.2.3" % Test,
"org.scalatestplus" %%% "scalacheck-1-14" % "3.2.2.0" % Test,
"org.scalacheck" %%% "scalacheck" % "1.14.3" % Test,
"com.chuusai" %% "shapeless" % "2.3.3" % Test,
).map(_.withDottyCompat(scalaVersion.value)),
libraryDependencies += {
if (isDotty.value)
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value % Provided
else
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided
},
libraryDependencies ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq()
case Some((3, _)) => Nil
case _ => Seq(compilerPlugin(("org.scalamacros" % "paradise" % "2.1.1").cross(CrossVersion.full)))
}),
unmanagedSourceDirectories in Compile += {
//val sourceDir = (sourceDirectory in Compile).value
// ^ gives jvm/src/main, for some reason
val sourceDir = baseDirectory.value.getParentFile / "shared/src/main"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 13 => sourceDir / "scala-2.13+"
case _ => sourceDir / "scala-2.13-"
case Some((2, n)) if n < 13 => sourceDir / "scala-2.13-"
case _ => sourceDir / "scala-2.13+"
}
},
Seq((Compile, "main"), (Test, "test")).map {
case (conf, dir) =>
conf / unmanagedSourceDirectories ++= {
val sourceDir = baseDirectory.value.getParentFile / s"shared/src/$dir"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => List(sourceDir / "scala-2")
case Some((3, _)) => List(sourceDir / "scala-3")
case _ => Nil
}
},
},
sourceGenerators in Compile += Def.task {
val dir = (sourceManaged in Compile).value

Expand Down Expand Up @@ -218,7 +243,7 @@ lazy val `play-jsonJS` = `play-json`.js

lazy val `play-jsonJVM` = `play-json`.jvm.settings(
libraryDependencies ++=
jacksons ++ specs2 :+ (
jacksons ++ specs2(scalaVersion.value) :+ (
"ch.qos.logback" % "logback-classic" % "1.2.3" % Test
),
unmanagedSourceDirectories in Test ++= (baseDirectory.value.getParentFile.getParentFile / "docs/manual/working/scalaGuide" ** "code").get
Expand All @@ -229,7 +254,7 @@ lazy val `play-json-joda` = project
.enablePlugins(Omnidoc, Publish)
.settings(
commonSettings ++ playJsonMimaSettings ++ Seq(
libraryDependencies ++= joda ++ specs2
libraryDependencies ++= joda ++ specs2(scalaVersion.value),
)
)
.dependsOn(`play-jsonJVM`)
Expand Down Expand Up @@ -260,7 +285,8 @@ lazy val docs = project
.configs(Docs)
.settings(
publish / skip := true,
libraryDependencies ++= specs2,
libraryDependencies ++= specs2(scalaVersion.value),
PlayDocsKeys.validateDocs := (if (isDotty.value) () else PlayDocsKeys.validateDocs.value),
PlayDocsKeys.scalaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "scalaGuide" ** "code").get,
PlayDocsKeys.resources += {
val apiDocs = (doc in (`play-jsonJVM`, Compile)).value
Expand Down
Loading

0 comments on commit 645d087

Please sign in to comment.