Skip to content

Commit fa063fe

Browse files
committed
Undeprecate mimaFailOnNoPrevious to build-wide opt-out
1 parent d165a5c commit fa063fe

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,42 @@ mimaBinaryIssueFilters ++= Seq(
8383
ProblemFilters.exclude[Problem]("com.example.mylibrary.internal.*"),
8484
)
8585
```
86+
87+
## Setting different mimaPreviousArtifacts
88+
89+
From time to time you may need to set `mimaPreviousArtifacts` according to some conditions. For
90+
instance, if you have already ported your project to Scala 2.13 and set it up for cross-building to Scala 2.13,
91+
but still haven't cut a release, you may want to define `mimaPreviousArtifacts` according to the Scala version,
92+
with something like:
93+
94+
```scala
95+
mimaPreviousArtifacts := {
96+
if (CrossVersion.partialVersion(scalaVersion.scala) == Some((2, 13))) Set.empty else {
97+
Set("com.example" %% "my-library" % "1.2.3")
98+
}
99+
}
100+
```
101+
102+
or perhaps using some of sbt 1.2's new API:
103+
104+
```scala
105+
import sbt.librarymanagement.{ SemanticSelector, VersionNumber }
106+
107+
mimaPreviousArtifacts := {
108+
if (VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector(">=2.13"))) Set.empty else {
109+
Set("com.example" %% "my-library" % "1.2.3")
110+
}
111+
}
112+
```
113+
114+
## Make mimaReportBinaryIssues not fail
115+
116+
The setting `mimaFailOnNoPrevious` (introduced in v0.4.0) defaults to `true` and will make
117+
`mimaReportBinaryIssues` fail if `mimaPreviousArtifacts` hasn't been set.
118+
119+
To make `mimaReportBinaryIssues` not fail you may want to do one of the following:
120+
121+
* set `mimaPreviousArtifacts` on all the projects that should be checking their binary compatibility
122+
* avoid calling `mimaPreviousArtifacts` when binary compatibility checking isn't needed
123+
* set `mimaFailOnNoPrevious := false` on specific projects that want to opt-out (alternatively `disablePlugins(MimaPlugin)`)
124+
* set `mimaFailOnNoPrevious in ThisBuild := false`, which disables it build-wide, effectively reverting back to the previous behaviour

sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaKeys.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ object MimaKeys extends MimaKeys
88
class MimaKeys {
99

1010
final val mimaFailOnProblem = settingKey[Boolean]("if true, fail the build on binary incompatibility detection.")
11+
final val mimaFailOnNoPrevious = settingKey[Boolean]("if true, fail the build if no previous artifacts are set.")
1112
final val mimaPreviousArtifacts = settingKey[Set[ModuleID]]("Previous released artifacts used to test binary compatibility.")
1213
final val mimaPreviousClassfiles = taskKey[Map[ModuleID, File]]("Directories or jars containing the previous class files used to test compatibility with a given module.")
1314
final val mimaCurrentClassfiles = taskKey[File]("Directory or jar containing the current class files used to test compatibility.")
@@ -22,7 +23,4 @@ class MimaKeys {
2223

2324
final val mimaCheckDirection = settingKey[String]("Compatibility checking direction; default is \"backward\", but can also be \"forward\" or \"both\".")
2425

25-
@deprecated("No longer used", "0.5.0")
26-
final val mimaFailOnNoPrevious = MimaPlugin.mimaFailOnNoPrevious
27-
2826
}

sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaPlugin.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ object MimaPlugin extends AutoPlugin {
7979
val s = streams.value
8080
val log = new SbtLogger(s)
8181
val projectName = name.value
82+
val failOnNoPrevious = mimaFailOnNoPrevious.value
8283
val currentClassfiles = mimaCurrentClassfiles.value
8384
val cp = (fullClasspath in mimaFindBinaryIssues).value
8485
val checkDirection = mimaCheckDirection.value
8586
mimaPreviousClassfiles.value match {
8687
case _: NoPreviousClassfiles.type =>
87-
sys.error(s"$projectName: mimaPreviousArtifacts not set, not analyzing binary compatibility.")
88+
val msg = s"$projectName: mimaPreviousArtifacts not set, not analyzing binary compatibility."
89+
if (failOnNoPrevious) sys.error(msg)
90+
else s.log.info(msg)
91+
Iterator.empty
8892
case previousClassfiles if previousClassfiles.isEmpty =>
8993
s.log.info(s"$projectName: mimaPreviousArtifacts is empty, not analyzing binary compatibility.")
9094
Iterator.empty
@@ -126,8 +130,4 @@ object MimaPlugin extends AutoPlugin {
126130
override def apply(key: K) = throw new NoSuchElementException(s"key not found: $key")
127131
}
128132

129-
// internal un-deprecated version
130-
private[mima] final val mimaFailOnNoPrevious =
131-
settingKey[Boolean]("if true, fail the build if no previous artifacts are set.")
132-
133133
}

0 commit comments

Comments
 (0)