Skip to content

Commit 0c2aa45

Browse files
committed
Fix cross build
1 parent 0993f7d commit 0c2aa45

File tree

4 files changed

+100
-79
lines changed

4 files changed

+100
-79
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ jobs:
6565
run: sbt ++${{ matrix.scala }} evicted undeclaredCompileDependenciesTest unusedCompileDependenciesTest dependencyCheckAggregate
6666

6767
- name: Build and test
68-
run: sbt ++${{ matrix.scala }} test scripted
68+
run: sbt ++${{ matrix.scala }} test
69+
70+
- name: Build and test sbt plugin
71+
if: ${{ matrix.scala == "2.12.13" }}
72+
run: sbt ++${{ matrix.scala }} scripted
6973

7074
- name: Compress target directories
7175
run: tar cf targets.tar sbt/target target doc-templates/target cli/target core/target project/target
@@ -83,7 +87,7 @@ jobs:
8387
strategy:
8488
matrix:
8589
os: [ubuntu-latest]
86-
scala: [2.12.12]
90+
scala: [2.12.13]
8791
java: [adopt@1.8]
8892
runs-on: ${{ matrix.os }}
8993
steps:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For most use cases you should add Scala2PlantUML as a global plugin since your b
3333
Create `~/.sbt/1.0/plugins/scala2PlantUML.sbt` containing:
3434

3535
```text
36-
addSbtPlugin("nz.co.bottech" % "sbt-scala2plantuml" % "0.1.1")
36+
addSbtPlugin("nz.co.bottech" % "sbt-scala2plantuml" % "0.1.2")
3737
```
3838

3939
## CLI
@@ -49,7 +49,7 @@ cs install --channel https://git.io/Jqv1i scala2plantuml
4949
### Usage
5050

5151
```text
52-
Scala2PlantUML version 0.1.1
52+
Scala2PlantUML version 0.1.2
5353
Usage: scala2plantuml [options] symbol
5454
5555
Scala2PlantUML generates PlantUML Class Diagrams from Scala SemanticDB files.

build.sbt

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import explicitdeps.ModuleFilter
21
import sbt.Def
32

43
val scala212 = "2.12.13"
@@ -11,21 +10,25 @@ val scoptVersion = "4.0.0"
1110
val slf4jVersion = "1.7.30"
1211
val utestVersion = "0.7.7"
1312

13+
val checkTasks = List(
14+
"scalafmtCheckAll",
15+
"scalastyle",
16+
"versionPolicyCheck",
17+
"githubWorkflowCheck",
18+
"mdocCheck",
19+
"evicted",
20+
"undeclaredCompileDependenciesTest",
21+
"unusedCompileDependenciesTest",
22+
"dependencyCheckAggregate",
23+
"test",
24+
"scripted"
25+
)
26+
1427
addCommandAlias(
1528
"check",
16-
List(
17-
"scalafmtCheckAll",
18-
"scalastyle",
19-
"+versionPolicyCheck",
20-
"+githubWorkflowCheck",
21-
"mdocCheck",
22-
"evicted",
23-
"+undeclaredCompileDependenciesTest",
24-
"+unusedCompileDependenciesTest",
25-
"+dependencyCheckAggregate",
26-
"+test",
27-
"scripted"
28-
).mkString("; ")
29+
supportedScalaVersions.flatMap { version =>
30+
s"++$version" :: checkTasks.filterNot(_ == "scripted" && version == scala213)
31+
}.mkString("; ")
2932
)
3033

3134
addCommandAlias(
@@ -62,7 +65,12 @@ inThisBuild(
6265
),
6366
name = Some("Check dependencies")
6467
),
65-
WorkflowStep.Sbt(List("test", "scripted"), name = Some("Build and test"))
68+
WorkflowStep.Sbt(List("test"), name = Some("Build and test")),
69+
WorkflowStep.Sbt(
70+
List("scripted"),
71+
name = Some("Build and test sbt plugin"),
72+
cond = Some(s"""$${{ matrix.scala == "$scala212" }}""")
73+
)
6674
),
6775
githubWorkflowPublish := List(
6876
WorkflowStep.Sbt(
@@ -77,7 +85,10 @@ inThisBuild(
7785
),
7886
githubWorkflowPublishTargetBranches := List(RefPredicate.StartsWith(Ref.Tag("v"))),
7987
githubWorkflowTargetTags ++= Seq("v*"),
80-
versionPolicyFirstVersion := Some("0.1.1"),
88+
// This needs to be set otherwise the GitHub workflow plugin gets confused about which
89+
// version to use for the publish job.
90+
scalaVersion := scala212,
91+
versionPolicyFirstVersion := Some("0.1.2"),
8192
versionPolicyIntention := Compatibility.BinaryAndSourceCompatible,
8293
versionScheme := Some("early-semver")
8394
)
@@ -101,9 +112,9 @@ val commonProjectSettings = List(
101112

102113
val metaProjectSettings = List(
103114
crossScalaVersions := Nil,
104-
publish / skip := true,
105115
mimaFailOnNoPrevious := false,
106-
mimaPreviousArtifacts := Set.empty
116+
mimaPreviousArtifacts := Set.empty,
117+
publish / skip := true
107118
)
108119

109120
val libraryProjectSettings = commonProjectSettings
@@ -158,22 +169,27 @@ lazy val sbtProject = (project in file("sbt"))
158169
.enablePlugins(SbtPlugin)
159170
.settings(commonProjectSettings)
160171
.settings(
161-
libraryDependencies ++= collectionsCompatibilityDependency.value,
162-
libraryDependencies ++= List(
163-
"org.scala-sbt" %% "collections" % sbtVersion.value,
164-
"org.scala-sbt" %% "command" % sbtVersion.value,
165-
"org.scala-sbt" % "compiler-interface" % "1.4.4",
166-
"org.scala-sbt" %% "completion" % sbtVersion.value,
167-
"org.scala-sbt" %% "core-macros" % sbtVersion.value,
168-
"org.scala-sbt" %% "io" % "1.4.0",
169-
"org.scala-sbt" %% "librarymanagement-core" % "1.4.3",
170-
"org.scala-sbt" %% "main" % sbtVersion.value,
171-
"org.scala-sbt" %% "main-settings" % sbtVersion.value,
172-
"org.scala-sbt" % "sbt" % sbtVersion.value,
173-
"org.scala-sbt" %% "task-system" % sbtVersion.value,
174-
"org.scala-sbt" %% "util-logging" % sbtVersion.value,
175-
"org.scala-sbt" %% "util-position" % sbtVersion.value
176-
),
172+
libraryDependencies ++= {
173+
// Don't add dependencies when the rest of the build is cross building with Scala 2.13
174+
// otherwise it will cause a whole lot of resolution failures.
175+
if ((core / isScala213).value) Nil
176+
else
177+
collectionsCompatibilityDependency.value ++ List(
178+
"org.scala-sbt" %% "collections" % sbtVersion.value,
179+
"org.scala-sbt" %% "command" % sbtVersion.value,
180+
"org.scala-sbt" % "compiler-interface" % "1.4.4",
181+
"org.scala-sbt" %% "completion" % sbtVersion.value,
182+
"org.scala-sbt" %% "core-macros" % sbtVersion.value,
183+
"org.scala-sbt" %% "io" % "1.4.0",
184+
"org.scala-sbt" %% "librarymanagement-core" % "1.4.3",
185+
"org.scala-sbt" %% "main" % sbtVersion.value,
186+
"org.scala-sbt" %% "main-settings" % sbtVersion.value,
187+
"org.scala-sbt" % "sbt" % sbtVersion.value,
188+
"org.scala-sbt" %% "task-system" % sbtVersion.value,
189+
"org.scala-sbt" %% "util-logging" % sbtVersion.value,
190+
"org.scala-sbt" %% "util-position" % sbtVersion.value
191+
)
192+
},
177193
name := s"sbt-${(LocalRootProject / name).value}",
178194
scriptedBufferLog := false,
179195
scriptedDependencies := {
@@ -198,11 +214,7 @@ lazy val docs = (project in file("doc-templates"))
198214
// After a release we need to update the docs and do a git push.
199215
"VERSION" -> versionPolicyPreviousVersions.value.lastOption.getOrElse(versionPolicyFirstVersion.value.get)
200216
),
201-
unusedCompileDependenciesFilter -= new ModuleFilter {
202-
203-
override def apply(a: ModuleID) =
204-
moduleFilter("org.scalameta", "mdoc_2.12.12").apply(a)
205-
}
217+
unusedCompileDependenciesFilter -= moduleFilter("org.scalameta", "mdoc*")
206218
)
207219

208220
def isScala213Setting: Def.Initialize[Boolean] = Def.setting {
Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
1+
import explicitdeps.ExplicitDepsPlugin
2+
import explicitdeps.ExplicitDepsPlugin.autoImport._
13
import sbt.Keys._
24
import sbt._
35
import sbt.plugins.SbtPlugin
46

57
// This is all the crazy hacks to get cross compiling working with an sub-project that is an sbt plugin.
68
object SbtSubProjectPluginPlugin extends AutoPlugin {
79

8-
override def trigger = allRequirements
9-
override def requires = SbtPlugin
10+
override def trigger: PluginTrigger = allRequirements
11+
override def requires: Plugins = ExplicitDepsPlugin && SbtPlugin
12+
13+
private val sspppIsScala213 = settingKey[Boolean]("Checks if the current Scala version is 2.13")
1014

1115
override def projectSettings: Seq[Def.Setting[_]] =
1216
List(
1317
crossScalaVersions := Nil,
14-
evicted := evictedTask.value,
15-
skip := skipTask.value,
16-
update := updateTask.value
18+
libraryDependencies := libraryDependenciesSetting.value,
19+
projectDependencies := projectDependenciesTask.value,
20+
sspppIsScala213 := {
21+
if (isScala213(scalaVersion.value))
22+
throw new IllegalStateException("sbt project must not use Scala 2.13. Did you force the version with '+'?")
23+
isScala213Setting.value
24+
},
25+
// We can't skip this as it has to run at least once or sbt complains.
26+
update / skip := false,
27+
// Skip everything else otherwise it will just fail.
28+
skip := sspppIsScala213.value,
29+
undeclaredCompileDependenciesFilter -= moduleFilter()
1730
)
1831

19-
private def evictedTask = Def.task {
20-
val report = update.value
21-
EvictionWarning(ivyModule.value, (evicted / evictionWarningOptions).value, report)
32+
private def isScala213Setting = Def.setting {
33+
val versions =
34+
scalaVersion.all(ScopeFilter(inDependencies(ThisProject, transitive = true, includeRoot = false))).value
35+
versions.exists(isScala213)
2236
}
2337

24-
private def skipTask =
25-
Def.task {
26-
val versions =
27-
scalaVersion.all(ScopeFilter(inDependencies(ThisProject, transitive = false, includeRoot = false))).value
28-
versions.exists { version =>
29-
CrossVersion.partialVersion(version) match {
30-
case Some((2, n)) if n == 13 => true
31-
case _ => false
32-
}
33-
}
38+
private def isScala213(version: String) =
39+
CrossVersion.partialVersion(version) match {
40+
case Some((2, n)) if n == 13 => true
41+
case _ => false
3442
}
3543

36-
//noinspection MutatorLikeMethodIsParameterless
37-
private def updateTask =
38-
Def.task {
39-
if (skip.value) {
40-
val configurations = ivyModule.value.configurations
41-
dummyUpdateReport(configurations)
42-
} else update.value
44+
private def projectDependenciesTask = Def.task {
45+
// Remove all project dependencies for Scala 2.13 as they will not resolve when cross building.
46+
if (sspppIsScala213.value) {
47+
Seq.empty
48+
} else {
49+
projectDependencies.value
4350
}
51+
}
4452

45-
private def dummyUpdateReport(configurations: Vector[Configuration]) =
46-
UpdateReport(
47-
new File("."),
48-
configurations.map(dummyConfigurationReport),
49-
UpdateStats(-1L, -1L, -1L, cached = false),
50-
Map.empty
51-
)
52-
53-
private def dummyConfigurationReport(configuration: Configuration) =
54-
ConfigurationReport(configuration, Vector.empty, Vector.empty)
55-
53+
private def libraryDependenciesSetting = Def.setting {
54+
// Remove all library dependencies for Scala 2.13 as they will not resolve when cross building.
55+
if (sspppIsScala213.value) {
56+
Seq.empty
57+
} else {
58+
libraryDependencies.value
59+
}
60+
}
5661
}

0 commit comments

Comments
 (0)