diff --git a/build.sbt b/build.sbt index 810617b04..590f260bc 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,15 @@ import sbt.Def +import MimaSettings.mimaSettings + +/** + * As of zio-kafka version 2.8.0 releases are binary compatible. This is checked with Mima. + * + * Keep this value set to the oldest minor release (with patch version set to "0") that is still binary compatible. + * + * Set this value to `None` when master is _not_ binary compatible with the latest minor release, the next release shall + * increase the minor version. + */ +lazy val binCompatVersionToCompare = None // Some("2.8.0") lazy val kafkaVersion = "3.7.0" lazy val embeddedKafkaVersion = "3.7.0" // Should be the same as kafkaVersion, except for the patch part @@ -66,9 +77,10 @@ val excludeInferAny = { options: Seq[String] => options.filterNot(Set("-Xlint:in lazy val root = project .in(file(".")) .settings( - name := "zio-kafka", - publish / skip := true, - crossScalaVersions := Nil // https://www.scala-sbt.org/1.x/docs/Cross-Build.html#Cross+building+a+project+statefully + name := "zio-kafka", + publish / skip := true, + crossScalaVersions := Nil, // https://www.scala-sbt.org/1.x/docs/Cross-Build.html#Cross+building+a+project+statefully, + commands += lint ) .aggregate( zioKafka, @@ -104,6 +116,7 @@ lazy val zioKafka = .enablePlugins(BuildInfoPlugin) .settings(stdSettings("zio-kafka")) .settings(buildInfoSettings("zio.kafka")) + .settings(mimaSettings(binCompatVersionToCompare, failOnProblem = true)) .settings(enableZIO(enableStreaming = true)) .settings( libraryDependencies ++= Seq( @@ -126,6 +139,7 @@ lazy val zioKafkaTestkit = .dependsOn(zioKafka) .enablePlugins(BuildInfoPlugin) .settings(stdSettings("zio-kafka-testkit")) + .settings(mimaSettings(binCompatVersionToCompare, failOnProblem = false)) .settings( libraryDependencies ++= Seq( "dev.zio" %% "zio" % zioVersion.value, @@ -187,6 +201,7 @@ lazy val zioKafkaExample = addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt") addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck") +addCommandAlias("mimaCheck", "+zioKafka/mimaReportBinaryIssues;+zioKafkaTestkit/mimaReportBinaryIssues") lazy val docs = project .in(file("zio-kafka-docs")) @@ -206,3 +221,9 @@ lazy val docs = project ) .enablePlugins(WebsitePlugin) .dependsOn(zioKafka, zioKafkaTestkit) + +// Extend 'lint' with mimaCheck +lazy val lint = { + val defaultLint = zio.sbt.Commands.ComposableCommand.lint + defaultLint.copy(commandStrings = defaultLint.commandStrings :+ "mimaCheck").toCommand +} diff --git a/project/MimaSettings.scala b/project/MimaSettings.scala new file mode 100644 index 000000000..71cdbafe6 --- /dev/null +++ b/project/MimaSettings.scala @@ -0,0 +1,24 @@ +import com.typesafe.tools.mima.core.* +import com.typesafe.tools.mima.core.ProblemFilters.* +import com.typesafe.tools.mima.plugin.MimaKeys.* +import sbt.* +import sbt.Keys.{ name, organization } + +object MimaSettings { + + def mimaSettings(binCompatVersionToCompare: Option[String], failOnProblem: Boolean): Seq[Def.Setting[?]] = + binCompatVersionToCompare match { + case None => + Seq(mimaPreviousArtifacts := Set.empty) + case Some(binCompatVersion) => + Seq( + mimaPreviousArtifacts := Set(organization.value %% name.value % binCompatVersion), + mimaBinaryIssueFilters ++= Seq( + exclude[Problem]("zio.kafka.consumer.internal.*") + ), + mimaFailOnProblem := failOnProblem + ) + + } + +} diff --git a/project/plugins.sbt b/project/plugins.sbt index b95081aa5..ecab40995 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -7,5 +7,6 @@ addSbtPlugin("dev.zio" % "zio-sbt-ci" % zioSbtVersion) addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0") addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.1") addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.0") +addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3") resolvers ++= Resolver.sonatypeOssRepos("public")