From fa063fe4b29c3ae0aab98137777fa4bc86c30a40 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 12 Jul 2019 12:00:58 +0100 Subject: [PATCH] Undeprecate mimaFailOnNoPrevious to build-wide opt-out --- README.md | 39 +++++++++++++++++++ .../typesafe/tools/mima/plugin/MimaKeys.scala | 4 +- .../tools/mima/plugin/MimaPlugin.scala | 10 ++--- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 371ae0da..36fffd45 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,42 @@ mimaBinaryIssueFilters ++= Seq( ProblemFilters.exclude[Problem]("com.example.mylibrary.internal.*"), ) ``` + +## Setting different mimaPreviousArtifacts + +From time to time you may need to set `mimaPreviousArtifacts` according to some conditions. For +instance, if you have already ported your project to Scala 2.13 and set it up for cross-building to Scala 2.13, +but still haven't cut a release, you may want to define `mimaPreviousArtifacts` according to the Scala version, +with something like: + +```scala +mimaPreviousArtifacts := { + if (CrossVersion.partialVersion(scalaVersion.scala) == Some((2, 13))) Set.empty else { + Set("com.example" %% "my-library" % "1.2.3") + } +} +``` + +or perhaps using some of sbt 1.2's new API: + +```scala +import sbt.librarymanagement.{ SemanticSelector, VersionNumber } + +mimaPreviousArtifacts := { + if (VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector(">=2.13"))) Set.empty else { + Set("com.example" %% "my-library" % "1.2.3") + } +} +``` + +## Make mimaReportBinaryIssues not fail + +The setting `mimaFailOnNoPrevious` (introduced in v0.4.0) defaults to `true` and will make +`mimaReportBinaryIssues` fail if `mimaPreviousArtifacts` hasn't been set. + +To make `mimaReportBinaryIssues` not fail you may want to do one of the following: + +* set `mimaPreviousArtifacts` on all the projects that should be checking their binary compatibility +* avoid calling `mimaPreviousArtifacts` when binary compatibility checking isn't needed +* set `mimaFailOnNoPrevious := false` on specific projects that want to opt-out (alternatively `disablePlugins(MimaPlugin)`) +* set `mimaFailOnNoPrevious in ThisBuild := false`, which disables it build-wide, effectively reverting back to the previous behaviour diff --git a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaKeys.scala b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaKeys.scala index 3546adbe..25f1db21 100644 --- a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaKeys.scala +++ b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaKeys.scala @@ -8,6 +8,7 @@ object MimaKeys extends MimaKeys class MimaKeys { final val mimaFailOnProblem = settingKey[Boolean]("if true, fail the build on binary incompatibility detection.") + final val mimaFailOnNoPrevious = settingKey[Boolean]("if true, fail the build if no previous artifacts are set.") final val mimaPreviousArtifacts = settingKey[Set[ModuleID]]("Previous released artifacts used to test binary compatibility.") final val mimaPreviousClassfiles = taskKey[Map[ModuleID, File]]("Directories or jars containing the previous class files used to test compatibility with a given module.") final val mimaCurrentClassfiles = taskKey[File]("Directory or jar containing the current class files used to test compatibility.") @@ -22,7 +23,4 @@ class MimaKeys { final val mimaCheckDirection = settingKey[String]("Compatibility checking direction; default is \"backward\", but can also be \"forward\" or \"both\".") - @deprecated("No longer used", "0.5.0") - final val mimaFailOnNoPrevious = MimaPlugin.mimaFailOnNoPrevious - } diff --git a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaPlugin.scala b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaPlugin.scala index b10774f8..65ffcaef 100644 --- a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaPlugin.scala +++ b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaPlugin.scala @@ -79,12 +79,16 @@ object MimaPlugin extends AutoPlugin { val s = streams.value val log = new SbtLogger(s) val projectName = name.value + val failOnNoPrevious = mimaFailOnNoPrevious.value val currentClassfiles = mimaCurrentClassfiles.value val cp = (fullClasspath in mimaFindBinaryIssues).value val checkDirection = mimaCheckDirection.value mimaPreviousClassfiles.value match { case _: NoPreviousClassfiles.type => - sys.error(s"$projectName: mimaPreviousArtifacts not set, not analyzing binary compatibility.") + val msg = s"$projectName: mimaPreviousArtifacts not set, not analyzing binary compatibility." + if (failOnNoPrevious) sys.error(msg) + else s.log.info(msg) + Iterator.empty case previousClassfiles if previousClassfiles.isEmpty => s.log.info(s"$projectName: mimaPreviousArtifacts is empty, not analyzing binary compatibility.") Iterator.empty @@ -126,8 +130,4 @@ object MimaPlugin extends AutoPlugin { override def apply(key: K) = throw new NoSuchElementException(s"key not found: $key") } - // internal un-deprecated version - private[mima] final val mimaFailOnNoPrevious = - settingKey[Boolean]("if true, fail the build if no previous artifacts are set.") - }