From 874fe040ad7129a5cfa96c0e5f7944123cb3eb88 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Thu, 19 Oct 2023 11:51:31 +0200 Subject: [PATCH] feature: Cross-compile for Play 2.8 --- .circleci/config.yml | 8 +++---- build.sbt | 43 ++++++++++++++++++++++++++++++++++++-- project/Dependencies.scala | 17 +++++++++------ 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a89b81d..e11ca02 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2.1 orbs: - codacy: codacy/base@10.1.0 + codacy: codacy/base@10.9.0 workflows: version: 2 @@ -27,7 +27,7 @@ workflows: command: sbt scalafmtSbtCheck - run: name: Run tests - command: sbt test + command: sbt crossTest - run: name: Generate coverage report command: sbt coverageReport @@ -58,7 +58,7 @@ workflows: command: sbt retrieveGPGKeys - run: name: Create publish bundle - command: sbt publishSigned + command: sbt crossPublishSigned - run: name: Release bundle to Sonatype command: sbt sonatypeBundleRelease @@ -75,6 +75,6 @@ workflows: command: echo 'privateMvnPublish' > publishing.sbt - run: name: Publish to S3 - command: sbt publish + command: sbt crossPublish requires: - tag_version diff --git a/build.sbt b/build.sbt index 0ed59fb..9582f0f 100644 --- a/build.sbt +++ b/build.sbt @@ -2,6 +2,12 @@ name := """bitbucket-scala-client""" val scala212 = "2.12.10" +val play27 = "2.7.4" +val play28 = "2.8.2" + +lazy val playJsonVersion = settingKey[String]("The version of play-json used for building.") +ThisBuild / playJsonVersion := play27 + scalaVersion := scala212 scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Ywarn-adapted-args", "-Xlint") @@ -9,7 +15,9 @@ scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Ywarn-adapted-a resolvers += "Typesafe maven repository" at "https://repo.typesafe.com/typesafe/maven-releases/" -libraryDependencies ++= Dependencies.playJson ++ Seq("org.scalatest" %% "scalatest" % "3.0.8" % Test) +libraryDependencies ++= Dependencies.playJson(playJsonVersion.value) ++ Seq( + "org.scalatest" %% "scalatest" % "3.0.8" % Test +) organizationName := "Codacy" @@ -31,4 +39,35 @@ scmInfo := Some( pgpPassphrase := Option(System.getenv("SONATYPE_GPG_PASSPHRASE")) .map(_.toCharArray) -name := s"${name.value}_playjson${Dependencies.playVersion.split('.').take(2).mkString}" +name := s"${name.value}_playjson${playJsonVersion.value.split('.').take(2).mkString}" + +/** + * Given a command it creates an alias to run the command + * on the entire matrix of play and scala versions. + * If the command has `:` in it (like test:compile) + * the alias becomes crossTestCompile instead of crossTest:compile + * (which is not an allowed sbt alias name) + */ +def addCrossAlias(command: String) = { + val matrix = Seq(scala212 -> Seq(play27, play28)) + + addCommandAlias( + s"cross${command.split(':').map(_.capitalize).mkString}", + matrix + .flatMap { + case (scalaV, playVersions) => + s"""set ThisBuild / scalaVersion := "$scalaV"""" +: playVersions + .flatMap(playV => Seq(s"""set ThisBuild / playJsonVersion := "$playV"""", command)) + } + .mkString(";") + ) +} + +// List of crossX aliases. +// Add a command here if you want to call it for +// the entire playVersion / scalaVersion matrix +addCrossAlias("update") +addCrossAlias("compile") +addCrossAlias("test:compile") +addCrossAlias("test") +addCrossAlias("publishSigned") diff --git a/project/Dependencies.scala b/project/Dependencies.scala index b634768..7f9062e 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,12 +1,17 @@ import sbt._ object Dependencies { - val playVersion: String = "2.7.4" - val playJson = Seq( - "com.typesafe.play" %% "play-json-joda" % playVersion, - "com.typesafe.play" %% "play-ahc-ws-standalone" % "2.0.8", - "com.typesafe.play" %% "play-ws-standalone-json" % "2.0.8" - ) + def playJson(playJsonVersion: String) = { + val playwsVersion = + if (playJsonVersion.startsWith("2.8.")) "2.1.11" + else if (playJsonVersion.startsWith("2.7.")) "2.0.8" + else sys.error("Missing play-ws version. Check the compatible version based on its pom") + Seq( + "com.typesafe.play" %% "play-json-joda" % playJsonVersion, + "com.typesafe.play" %% "play-ahc-ws-standalone" % playwsVersion, + "com.typesafe.play" %% "play-ws-standalone-json" % playwsVersion + ) + } }