Skip to content

Commit c8c8794

Browse files
Ensure multi-module SBT plugins respect excludedModules setting (#199)
* Ensure multi-module SBT plugins respect `excludedModules` setting Co-authored-by: Julien Richard-Foy <[email protected]>
1 parent 821df30 commit c8c8794

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ object SbtVersionPolicySettings {
127127
val excludedModules = ignoredModulesOfCurrentBuild.value
128128
val extractVersion = versionPolicyModuleVersionExtractor.value
129129

130+
log.debug(s"Computing module dependencies excluding ${excludedModules}")
130131
val currentDependencies = DependencyCheck.modulesOf(compileReport, excludedModules, sv, sbv, extractVersion, log)
132+
log.debug(s"Computed dependencies: ${currentDependencies.keySet}")
131133

132134
val reconciliations =
133135
DependencySchemes(
@@ -449,9 +451,15 @@ object SbtVersionPolicySettings {
449451
val projectCrossVersion = (projectRef / crossVersion).value
450452
val projectScalaVersion = (projectRef / scalaVersion).value
451453
val projectScalaBinaryVersion = (projectRef / scalaBinaryVersion).value
454+
val isSbtPlugin = (projectRef / sbtPlugin).value
452455
if (versionRegex.findFirstMatchIn(projectVersion).isDefined) {
456+
// Our goal is to compute the set of submodule names that should be excluded
457+
// from dependency checks.
458+
// For some reason, the compilation report returned by sbt adds a Scala binary
459+
// version suffix to the module names except for sbt plugins.
453460
val nameWithBinarySuffix =
454-
CrossVersion(projectCrossVersion, projectScalaVersion, projectScalaBinaryVersion)
461+
if (isSbtPlugin) projectName
462+
else CrossVersion(projectCrossVersion, projectScalaVersion, projectScalaBinaryVersion)
455463
.fold(projectName)(_ (projectName))
456464
val module = projectOrganization -> nameWithBinarySuffix
457465
Some(module)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
ThisBuild / scalaVersion := "2.12.18"
2+
ThisBuild / organization := "com.example"
3+
ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible
4+
5+
val a_1 =
6+
project
7+
.settings(
8+
name := "ignored-internal-dependencies-a",
9+
version := "1.0.0"
10+
)
11+
12+
val b_1 =
13+
project
14+
.enablePlugins(SbtPlugin)
15+
.settings(
16+
name := "ignored-internal-dependencies-b",
17+
version := "1.0.0"
18+
)
19+
20+
val c_1 =
21+
project
22+
.enablePlugins(SbtPlugin)
23+
.settings(
24+
name := "ignored-internal-dependencies-c",
25+
version := "1.0.0"
26+
)
27+
.dependsOn(a_1, b_1)
28+
29+
val a_2 =
30+
project
31+
.settings(
32+
name := "ignored-internal-dependencies-a",
33+
version := "2.0.0"
34+
)
35+
36+
val b_2 =
37+
project
38+
.enablePlugins(SbtPlugin)
39+
.settings(
40+
name := "ignored-internal-dependencies-b",
41+
version := "2.0.0"
42+
)
43+
44+
val c_2 =
45+
project
46+
.enablePlugins(SbtPlugin)
47+
.settings(
48+
name := "ignored-internal-dependencies-c",
49+
version := "1.0.1"
50+
)
51+
.dependsOn(a_2, b_2)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % sys.props("plugin.version"))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Publish v1.0.0 of modules
2+
> a_1/publishLocal
3+
> b_1/publishLocal
4+
> c_1/publishLocal
5+
6+
# Checking dependency issues fails because internal dependencies bumped their major version
7+
-> c_2/versionPolicyReportDependencyIssues
8+
9+
# Explicitly ignore the major version bump makes versionPolicyReportDependencyIssues pass
10+
> set c_2/versionPolicyIgnoredInternalDependencyVersions := Some("2.0.0".r)
11+
> c_2/versionPolicyReportDependencyIssues

0 commit comments

Comments
 (0)