From 2e864a624d32a522640a3d59876740a5d85ff80b Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 27 May 2020 15:26:36 +0200 Subject: [PATCH] Add basic defaults for mimaPreviousArtifacts Kind of like sbt-mima-version-check --- .../SbtCompatibilityMima.scala | 20 +++++++++++++++++++ .../sbt-compatibility/simple/build.sbt | 18 ++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/main/scala/sbtcompatibility/SbtCompatibilityMima.scala diff --git a/src/main/scala/sbtcompatibility/SbtCompatibilityMima.scala b/src/main/scala/sbtcompatibility/SbtCompatibilityMima.scala new file mode 100644 index 0000000..1ad660c --- /dev/null +++ b/src/main/scala/sbtcompatibility/SbtCompatibilityMima.scala @@ -0,0 +1,20 @@ +package sbtcompatibility + +import com.typesafe.tools.mima.plugin.MimaPlugin +import sbt.{AutoPlugin, Def, Keys} +import sbtcompatibility.version.Version + +object SbtCompatibilityMima extends AutoPlugin { + + override def trigger = allRequirements + override def requires = MimaPlugin + + override def projectSettings = Def.settings( + MimaPlugin.autoImport.mimaPreviousArtifacts := { + val projId = Keys.projectID.value + val versions = Version.latestCompatibleWith(sbt.Keys.version.value).toSet + versions.map(version => projId.withRevision(version)) + } + ) + +} diff --git a/src/sbt-test/sbt-compatibility/simple/build.sbt b/src/sbt-test/sbt-compatibility/simple/build.sbt index e272680..25194ee 100644 --- a/src/sbt-test/sbt-compatibility/simple/build.sbt +++ b/src/sbt-test/sbt-compatibility/simple/build.sbt @@ -44,6 +44,7 @@ lazy val d = project ), compatibilityDefaultReconciliation := lmcoursier.definitions.Reconciliation.Strict, checkFails, + checkMimaPreviousArtifactsSet, version := "0.1.1" ) @@ -52,17 +53,28 @@ inThisBuild(List( organization := "io.github.alexarchambault.sbtcompatibility.test", )) +lazy val check = taskKey[Unit]("") + lazy val shared = Def.settings( - compatibilityPreviousArtifacts := compatibilityAutoPreviousArtifacts.value + compatibilityPreviousArtifacts := compatibilityAutoPreviousArtifacts.value, + check := {} ) -lazy val check = taskKey[Unit]("") - lazy val checkFails = Def.settings( check := { + check.value val direction = compatibilityCheckDirection.value val reports = compatibilityFindDependencyIssues.value val failed = reports.exists(!_._2.validated(direction)) assert(failed, s"Expected a failed report in $reports") } ) + +lazy val checkMimaPreviousArtifactsSet = Def.settings( + check := { + check.value + val previousArtifacts = mimaPreviousArtifacts.value + val versions = previousArtifacts.map(_.revision) + assert(versions.nonEmpty, "No MiMa previous artifact found") + } +)