Skip to content

Commit

Permalink
Add basic defaults for mimaPreviousArtifacts
Browse files Browse the repository at this point in the history
Kind of like sbt-mima-version-check
  • Loading branch information
alexarchambault committed May 27, 2020
1 parent cec9539 commit 2e864a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/main/scala/sbtcompatibility/SbtCompatibilityMima.scala
Original file line number Diff line number Diff line change
@@ -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))
}
)

}
18 changes: 15 additions & 3 deletions src/sbt-test/sbt-compatibility/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ lazy val d = project
),
compatibilityDefaultReconciliation := lmcoursier.definitions.Reconciliation.Strict,
checkFails,
checkMimaPreviousArtifactsSet,
version := "0.1.1"
)

Expand All @@ -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")
}
)

0 comments on commit 2e864a6

Please sign in to comment.