Skip to content

Commit

Permalink
Ensure multi-module SBT plugins respect excludedModules setting (#199)
Browse files Browse the repository at this point in the history
* Ensure multi-module SBT plugins respect `excludedModules` setting

Co-authored-by: Julien Richard-Foy <julien@richard-foy.fr>
  • Loading branch information
alejandrohdezma and julienrf authored Apr 23, 2024
1 parent 821df30 commit c8c8794
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % sys.props("plugin.version"))
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c8c8794

Please sign in to comment.