Skip to content

Commit

Permalink
Upgrade to sbt 1.5.0 and use dynver and mima plugins directly
Browse files Browse the repository at this point in the history
- Upgrade sbt to 1.5.0
- Remove sbt-git-versioning
- Add sbt-dynver and sbt-mima plugins
- Upgrade Scala versions
- Upgrade scalatest to 3.2.7
- Upgrade scalacheck-ops to 2.6.0
- Update travis build to match
- Update .gitignore for new version of sbt
- Fix flaky test
- Use contains instead of ==
- Use randomOrThrow() instead of .getOrThrow
  • Loading branch information
jeffmay committed Apr 19, 2021
1 parent 256f9e0 commit cd1c1e7
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*.log

# sbt specific
.bsp
sbt.json
.cache
.history
.lib/
Expand All @@ -14,6 +16,7 @@ project/plugins/project/

# IntelliJ Specific
.idea
*.iml

# Scala-IDE specific
.scala_dependencies
Expand Down
27 changes: 18 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
language: scala
scala:
- 2.13.1
- 2.13.5
jdk:
- openjdk8
- openjdk11

before_script:
# Download sbt because Travis can't find it automatically :(
- mkdir -p $HOME/.sbt/launchers/1.5.0/
- curl -L -o $HOME/.sbt/launchers/1.5.0/sbt-launch.jar https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.5.0/sbt-launch-1.5.0.jar

script:
- sbt clean coverage test coverageAggregate coverageOff
after_success:
# Upload coverage reports to codecov.io
- bash <(curl -s https://codecov.io/bash) -t 24961df6-494e-4024-b035-ad2aca2ed706
- sbt clean coverage +test coverageAggregate
# Upload coverage reports to codecov.io before checking for binary compatibility
- bash <(curl -s https://codecov.io/bash)
- sbt +mimaReportBinaryIssues

# Tricks to avoid unnecessary cache updates
- find $HOME/.sbt -name "*.lock" | xargs rm
- find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm
# Avoid unnecessary cache updates
before_cache:
- rm -fv $HOME/.ivy2/.sbt.ivy.lock
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete
- find $HOME/.sbt -name "*.lock" -print -delete

# These directories are cached to S3 at the end of the build
cache:
directories:
- $HOME/.cache/coursier
- $HOME/.ivy2/cache
- $HOME/.sbt/boot/
- $HOME/.sbt
42 changes: 16 additions & 26 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ ThisBuild / organizationName := "Rally Health"
ThisBuild / bintrayOrganization := Some("rallyhealth")
ThisBuild / bintrayRepository := "maven"

ThisBuild / licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT"))
scalaVersion := Scala_2_13
ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT"))

ThisBuild / resolvers += "Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases/"
ThisBuild / resolvers += Resolver.bintrayRepo("rallyhealth", "maven")

// don't publish the surrounding multi-project build
publish := {}
publishLocal := {}
// reload sbt when the build files change
Global / onChangedBuildSource := ReloadOnSourceChanges

// don't publish the aggregate root project
publish / skip := true
publishLocal / skip := true

// don't search for previous artifact of the root project
mimaFailOnNoPrevious := false

def commonProject(id: String, projectPath: String, scalacVersion: String): Project = {
val versionSuffix = scalacVersion match {
Expand All @@ -30,16 +37,16 @@ def commonProject(id: String, projectPath: String, scalacVersion: String): Proje
if (id.contains("test")) id else s"$id-v$majorVersion"
},

// set the Scala version to the given version
scalaVersion := scalacVersion,

// verify binary compatibility
mimaPreviousArtifacts := Set(organization.value %% name.value % "4.1.0"),

// set the source code directories to the shared project root
sourceDirectory := file(s"$projectPath/src").getAbsoluteFile,
Compile / sourceDirectory := file(s"$projectPath/src/main").getAbsoluteFile,
Test / sourceDirectory := file(s"$projectPath/src/test").getAbsoluteFile,

// Suppress semver check for libraries that were missed
semVerEnforceAfterVersion := Some("3.2.0"),

// Include all of the dependencies in the loader. The base loader will be the Application
// ClassLoader. All classes apart from system classes will be reloaded with each run instead
// of being cached between layers.
Expand All @@ -62,7 +69,7 @@ def commonProject(id: String, projectPath: String, scalacVersion: String): Proje
// disable publishing empty ScalaDocs
Compile / packageDoc / publishArtifact := false

).enablePlugins(SemVerPlugin)
)
}

def playSuffix(includePlayVersion: String): String = includePlayVersion match {
Expand Down Expand Up @@ -120,13 +127,6 @@ def playJsonOps(scalacVersion: String, includePlayVersion: String): Project = {
}
}
}.map(_ % Test),
//Suppress semver check for new play 2.8 modules
semVerEnforceAfterVersion := {
includePlayVersion match {
case Play_2_8 => Some("4.1.0")
case _ => None
}
},
)
.dependsOn(((scalacVersion, includePlayVersion) match {
case (Scala_2_11, Play_2_5) => Seq(
Expand Down Expand Up @@ -176,14 +176,6 @@ def playJsonTests(scalacVersion: String, includePlayVersion: String, includeScal
commonProject(id, projectPath, scalacVersion).settings(
Test / scalacOptions -= "-deprecation",

//Suppress semver check for new play 2.8 modules
semVerEnforceAfterVersion := {
(scalacVersion, includePlayVersion, includeScalaCheckVersion) match {
case (_, Play_2_8, _) => Some("4.1.0")
case _ => None
}
},

libraryDependencies ++= Seq(
scalaCheckOps(includeScalaCheckVersion),
scalaTest(includeScalaCheckVersion)
Expand Down Expand Up @@ -235,5 +227,3 @@ lazy val `play27-json-tests-sc13-212` = playJsonTests(Scala_2_12, Play_2_7, Scal
lazy val `play27-json-tests-sc14-213` = playJsonTests(Scala_2_13, Play_2_7, ScalaCheck_1_14)
lazy val `play28-json-tests-sc13-212` = playJsonTests(Scala_2_12, Play_2_8, ScalaCheck_1_14)
lazy val `play28-json-tests-sc14-213` = playJsonTests(Scala_2_13, Play_2_8, ScalaCheck_1_14)

Global / onChangedBuildSource := ReloadOnSourceChanges
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import org.scalacheck.{Arbitrary, Gen, Shrink}
import org.scalatest.exceptions.TestFailedException
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FlatSpecLike, Matchers}
import play.api.libs.json.Json
import play.api.libs.json.{Json, OFormat}
import play.api.libs.json.scalacheck.PlayJsonFormatFlatSpecExample.SampleException
import play.api.libs.json.scalatest.PlayJsonFormatSpec

import scala.language.implicitConversions

case class Example(value: String, nested: Seq[Example])

object Example {
implicit val format = Json.format[Example]
implicit val format: OFormat[Example] = Json.format[Example]
}

trait PlayJsonExampleGenerators {
Expand Down Expand Up @@ -80,15 +78,15 @@ with GeneratorDrivenPropertyChecks {
a[TestFailedException] shouldBe thrownBy {
fail(reason)
}
assert(lastFailReason == Some(reason))
assert(lastFailReason.contains(reason))
}

it should "call the doFail method when providing a cause" in {
lastFailCause = None
a[TestFailedException] shouldBe thrownBy {
fail(SampleException)
}
assert(lastFailCause == Some(SampleException))
assert(lastFailCause.contains(SampleException))
}

it should "call the doFail method when providing both a reason and a cause" in {
Expand All @@ -98,12 +96,12 @@ with GeneratorDrivenPropertyChecks {
a[TestFailedException] shouldBe thrownBy {
fail(reason, SampleException)
}
assert(lastFailCause == Some(SampleException))
assert(lastFailReason == Some(reason))
assert(lastFailCause.contains(SampleException))
assert(lastFailReason.contains(reason))
}

"PlayJsonFormatFlatSpecExample.shrink" should "use the implicit shrink" in {
val example = Arbitrary.arbitrary[Example].suchThat(_.nested.nonEmpty).getOrThrow
val example = genExample(1).randomOrThrow()
val ex = intercept[TestFailedException] {
val expected = example.copy(nested = Seq())
assertSameWithShrink(expected, example, Json.toJson(example))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import org.scalatest.exceptions.TestFailedException
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import org.scalatest.flatspec.AnyFlatSpecLike
import org.scalatest.matchers.should.Matchers
import play.api.libs.json.Json
import play.api.libs.json.{Json, OFormat}
import play.api.libs.json.scalacheck.PlayJsonFormatFlatSpecExample.SampleException
import play.api.libs.json.scalatest.PlayJsonFormatSpec

import scala.language.implicitConversions

case class Example(value: String, nested: Seq[Example])

object Example {
implicit val format = Json.format[Example]
implicit val format: OFormat[Example] = Json.format[Example]
}

trait PlayJsonExampleGenerators {
Expand Down Expand Up @@ -81,15 +79,15 @@ with ScalaCheckDrivenPropertyChecks {
a[TestFailedException] shouldBe thrownBy {
fail(reason)
}
assert(lastFailReason == Some(reason))
assert(lastFailReason.contains(reason))
}

it should "call the doFail method when providing a cause" in {
lastFailCause = None
a[TestFailedException] shouldBe thrownBy {
fail(SampleException)
}
assert(lastFailCause == Some(SampleException))
assert(lastFailCause.contains(SampleException))
}

it should "call the doFail method when providing both a reason and a cause" in {
Expand All @@ -99,12 +97,12 @@ with ScalaCheckDrivenPropertyChecks {
a[TestFailedException] shouldBe thrownBy {
fail(reason, SampleException)
}
assert(lastFailCause == Some(SampleException))
assert(lastFailReason == Some(reason))
assert(lastFailCause.contains(SampleException))
assert(lastFailReason.contains(reason))
}

"PlayJsonFormatFlatSpecExample.shrink" should "use the implicit shrink" in {
val example = Arbitrary.arbitrary[Example].suchThat(_.nested.nonEmpty).getOrThrow
val example = genExample(1).randomOrThrow()
val ex = intercept[TestFailedException] {
val expected = example.copy(nested = Seq())
assertSameWithShrink(expected, example, Json.toJson(example))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import play.api.libs.json.{Json, OFormat}
import play.api.libs.json.scalacheck.PlayJsonFormatFlatSpecExample.SampleException
import play.api.libs.json.scalatest.PlayJsonFormatSpec

import scala.language.implicitConversions

case class Example(value: String, nested: Seq[Example])

object Example {
Expand Down Expand Up @@ -104,7 +102,7 @@ with ScalaCheckDrivenPropertyChecks {
}

"PlayJsonFormatFlatSpecExample.shrink" should "use the implicit shrink" in {
val example = Arbitrary.arbitrary[Example].suchThat(_.nested.nonEmpty).getOrThrow
val example = genExample(1).randomOrThrow()
val ex = intercept[TestFailedException] {
val expected = example.copy(nested = Seq())
assertSameWithShrink(expected, example, Json.toJson(example))
Expand Down
29 changes: 15 additions & 14 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@ import sbt._

object Dependencies {

final val Play_2_5 = "2.5.18"
final val Play_2_6 = "2.6.19"
final val Play_2_7 = "2.7.4"
final val Play_2_8 = "2.8.3"
final val Play_2_5 = "2.5.19"
final val Play_2_6 = "2.6.25"
final val Play_2_7 = "2.7.9"
final val Play_2_8 = "2.8.7"

final val Scala_2_11 = "2.11.12"
final val Scala_2_12 = "2.12.6"
final val Scala_2_13 = "2.13.1"
final val Scala_2_12 = "2.12.12"
final val Scala_2_13 = "2.13.5"

final val ScalaCheck_1_12 = "1.12.5"
final val ScalaCheck_1_13 = "1.13.4"
final val ScalaCheck_1_12 = "1.12.6"
final val ScalaCheck_1_13 = "1.13.5"
final val ScalaCheck_1_14 = "1.14.3"

private val Play_2_6_JsonVersion = "2.6.10"
private val Play_2_7_JsonVersion = "2.7.4"
private val Play_2_8_JsonVersion = "2.8.1"
private val ScalaCheckOpsVersion = "2.2.1"
private val ScalaCheckOpsVersion = "2.6.0"
private val ScalaTest_2 = "2.2.6"
private val ScalaTest_3 = "3.0.5"
private val ScalaTest_3_1 = "3.1.0"
private val ScalaTest_3_2 = "3.2.7"

private val ScalaTestPlusScalaCheck_1_14_Version = "3.1.0.0"
private val ScalaTestPlusScalaCheckVersion = "3.2.0.0"

def playJson(playVersion: String): ModuleID = {
val playJsonVersion = playVersion match {
case Play_2_5 => Play_2_5
case Play_2_6 => Play_2_6_JsonVersion
case Play_2_7 => Play_2_7
case Play_2_7 => Play_2_7_JsonVersion
case Play_2_8 => Play_2_8_JsonVersion
}
"com.typesafe.play" %% "play-json" % playJsonVersion
Expand All @@ -47,14 +48,14 @@ object Dependencies {
val version = scalaCheckVersion match {
case ScalaCheck_1_12 => ScalaTest_2
case ScalaCheck_1_13 => ScalaTest_3
case ScalaCheck_1_14 => ScalaTest_3_1
case ScalaCheck_1_14 => ScalaTest_3_2
}
"org.scalatest" %% "scalatest" % version
}

def scalaTestPlusScalaCheck(scalaCheckVersion: String): ModuleID = {
val version = scalaCheckVersion match {
case ScalaCheck_1_14 => ScalaTestPlusScalaCheck_1_14_Version
case ScalaCheck_1_14 => ScalaTestPlusScalaCheckVersion
}
"org.scalatestplus" %% "scalacheck-1-14" % version
}
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.0
sbt.version=1.5.0
7 changes: 3 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
resolvers += Classpaths.sbtPluginReleases
resolvers += Resolver.bintrayIvyRepo("rallyhealth", "sbt-plugins")
resolvers += Resolver.url(
"bintray-sbt-plugin-releases",
url("https://dl.bintray.com/content/sbt/sbt-plugin-releases")
)(Resolver.ivyStylePatterns)

addSbtPlugin("com.rallyhealth.sbt" %% "sbt-git-versioning" % "1.2.2")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.6")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.6.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")

0 comments on commit cd1c1e7

Please sign in to comment.