From a2b5989b0c44994cddab6b9405479f9e06eaae98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Tue, 23 Apr 2024 17:52:07 +0200 Subject: [PATCH] Ensure multi-module SBT plugins respect `excludedModules` setting (#199) * Ensure multi-module SBT plugins respect `excludedModules` setting Co-authored-by: Julien Richard-Foy --- .../SbtVersionPolicySettings.scala | 10 +++- .../ignored-internal-sbt-plugin/build.sbt | 51 +++++++++++++++++++ .../project/plugins.sbt | 1 + .../ignored-internal-sbt-plugin/test | 11 ++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/build.sbt create mode 100644 sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/project/plugins.sbt create mode 100644 sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/test diff --git a/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala b/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala index 074164c..0e0d345 100644 --- a/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala +++ b/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala @@ -127,7 +127,9 @@ object SbtVersionPolicySettings { val excludedModules = ignoredModulesOfCurrentBuild.value val extractVersion = versionPolicyModuleVersionExtractor.value + log.debug(s"Computing module dependencies excluding ${excludedModules}") val currentDependencies = DependencyCheck.modulesOf(compileReport, excludedModules, sv, sbv, extractVersion, log) + log.debug(s"Computed dependencies: ${currentDependencies.keySet}") val reconciliations = DependencySchemes( @@ -449,9 +451,15 @@ object SbtVersionPolicySettings { val projectCrossVersion = (projectRef / crossVersion).value val projectScalaVersion = (projectRef / scalaVersion).value val projectScalaBinaryVersion = (projectRef / scalaBinaryVersion).value + val isSbtPlugin = (projectRef / sbtPlugin).value if (versionRegex.findFirstMatchIn(projectVersion).isDefined) { + // Our goal is to compute the set of submodule names that should be excluded + // from dependency checks. + // For some reason, the compilation report returned by sbt adds a Scala binary + // version suffix to the module names except for sbt plugins. val nameWithBinarySuffix = - CrossVersion(projectCrossVersion, projectScalaVersion, projectScalaBinaryVersion) + if (isSbtPlugin) projectName + else CrossVersion(projectCrossVersion, projectScalaVersion, projectScalaBinaryVersion) .fold(projectName)(_ (projectName)) val module = projectOrganization -> nameWithBinarySuffix Some(module) diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/build.sbt b/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/build.sbt new file mode 100644 index 0000000..6238017 --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/build.sbt @@ -0,0 +1,51 @@ +ThisBuild / scalaVersion := "2.12.18" +ThisBuild / organization := "com.example" +ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible + +val a_1 = + project + .settings( + name := "ignored-internal-dependencies-a", + version := "1.0.0" + ) + +val b_1 = + project + .enablePlugins(SbtPlugin) + .settings( + name := "ignored-internal-dependencies-b", + version := "1.0.0" + ) + +val c_1 = + project + .enablePlugins(SbtPlugin) + .settings( + name := "ignored-internal-dependencies-c", + version := "1.0.0" + ) + .dependsOn(a_1, b_1) + +val a_2 = + project + .settings( + name := "ignored-internal-dependencies-a", + version := "2.0.0" + ) + +val b_2 = + project + .enablePlugins(SbtPlugin) + .settings( + name := "ignored-internal-dependencies-b", + version := "2.0.0" + ) + +val c_2 = + project + .enablePlugins(SbtPlugin) + .settings( + name := "ignored-internal-dependencies-c", + version := "1.0.1" + ) + .dependsOn(a_2, b_2) diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/project/plugins.sbt b/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/project/plugins.sbt new file mode 100644 index 0000000..2843375 --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % sys.props("plugin.version")) diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/test b/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/test new file mode 100644 index 0000000..f1663f2 --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/ignored-internal-sbt-plugin/test @@ -0,0 +1,11 @@ +# Publish v1.0.0 of modules +> a_1/publishLocal +> b_1/publishLocal +> c_1/publishLocal + +# Checking dependency issues fails because internal dependencies bumped their major version +-> c_2/versionPolicyReportDependencyIssues + +# Explicitly ignore the major version bump makes versionPolicyReportDependencyIssues pass +> set c_2/versionPolicyIgnoredInternalDependencyVersions := Some("2.0.0".r) +> c_2/versionPolicyReportDependencyIssues