Skip to content

Commit

Permalink
Merge pull request #338 from dwijnand/bring-back-mimaFailOnNoPrevious
Browse files Browse the repository at this point in the history
Undeprecate mimaFailOnNoPrevious to build-wide opt-out
  • Loading branch information
dwijnand authored Jul 12, 2019
2 parents d165a5c + fa063fe commit 8c0b404
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")

}

0 comments on commit 8c0b404

Please sign in to comment.