Skip to content

Commit 4bd8888

Browse files
committed
Fix sbt project
1 parent e4f7533 commit 4bd8888

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,8 @@ jobs:
5252
- name: Check that workflows are up to date
5353
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
5454

55-
- name: Check formatting and style
56-
run: sbt ++${{ matrix.scala }} scalafmtCheckAll scalastyle
57-
58-
- name: Check version adheres to the policy
59-
run: sbt ++${{ matrix.scala }} versionPolicyCheck
60-
61-
- name: Check documentation has been generated
62-
run: sbt ++${{ matrix.scala }} mdocCheck
63-
64-
- name: Check dependencies
65-
run: sbt ++${{ matrix.scala }} evicted undeclaredCompileDependenciesTest unusedCompileDependenciesTest dependencyCheckAggregate
66-
67-
- name: Build and test
68-
run: sbt ++${{ matrix.scala }} test
55+
- name: Build, test and check libraries
56+
run: sbt ++${{ matrix.scala }} check
6957

7058
- name: Build and test sbt plugin
7159
if: matrix.scala == '2.12.13'

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ val utestVersion = "0.7.7"
1111
addCommandAlias(
1212
"devCheck",
1313
supportedScalaVersions.flatMap { version =>
14-
s"++$version" :: "check" :: (if (version == scala213) Nil else List("scripted"))
14+
s"++$version" :: "githubWorkflowCheck" :: "check" :: (if (version == scala213) Nil else List("scripted"))
1515
}.mkString(";")
1616
)
1717

@@ -166,7 +166,7 @@ lazy val sbtProject = (project in file("sbt"))
166166
libraryDependencies ++= {
167167
// Only add dependencies when the build is building with a Scala version that is
168168
// sbt compatible otherwise it will cause a whole lot of resolution failures.
169-
if (spspIsSbtCompatibleScalaVersion.value)
169+
if (spspCanBuild.value)
170170
collectionsCompatibilityDependency.value ++ List(
171171
"org.scala-sbt" %% "collections" % sbtVersion.value,
172172
"org.scala-sbt" %% "command" % sbtVersion.value,

project/ConditionalKeys.scala

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ object ConditionalKeys {
66
def settingDefaultIfSetting[A, B](
77
setting: Def.Initialize[A],
88
condition: Def.Initialize[B],
9-
p: B => Boolean,
10-
default: A
9+
default: => A
10+
)(
11+
p: B => Boolean
1112
): Def.Initialize[A] = Def.setting {
1213
if (p(condition.value)) {
1314
default
@@ -16,14 +17,15 @@ object ConditionalKeys {
1617
}
1718
}
1819

19-
def taskDefaultIfSkipped[A](task: TaskKey[A], default: A): Def.Initialize[Task[A]] =
20-
taskDefaultIfTask[A, Boolean](task, task / skip, identity, default)
20+
def taskDefaultIfSkipped[A](task: TaskKey[A], default: => A): Def.Initialize[Task[A]] =
21+
taskDefaultIfTask(task, task / skip, default)(identity)
2122

2223
def taskDefaultIfSetting[A, B](
2324
task: Def.Initialize[Task[A]],
2425
condition: Def.Initialize[B],
25-
p: B => Boolean,
26-
default: A
26+
default: => A
27+
)(
28+
p: B => Boolean
2729
): Def.Initialize[Task[A]] = Def.taskIf {
2830
if (p(condition.value)) {
2931
default
@@ -35,8 +37,9 @@ object ConditionalKeys {
3537
def taskDefaultIfTask[A, B](
3638
task: Def.Initialize[Task[A]],
3739
condition: Def.Initialize[Task[B]],
38-
p: B => Boolean,
39-
default: A
40+
default: => A
41+
)(
42+
p: B => Boolean
4043
): Def.Initialize[Task[A]] = Def.taskIf {
4144
if (p(condition.value)) {
4245
default
@@ -45,14 +48,15 @@ object ConditionalKeys {
4548
}
4649
}
4750

48-
def inputDefaultIfSkipped[A](input: InputKey[A], default: A): Def.Initialize[InputTask[A]] =
49-
inputDefaultIfTask[A, Boolean](input, input / skip, identity, default)
51+
def inputDefaultIfSkipped[A](input: InputKey[A], default: => A): Def.Initialize[InputTask[A]] =
52+
inputDefaultIfTask(input, input / skip, default)(identity)
5053

5154
def inputDefaultIfTask[A, B](
5255
input: InputKey[A],
5356
condition: Def.Initialize[Task[B]],
54-
p: B => Boolean,
55-
default: A
57+
default: => A
58+
)(
59+
p: B => Boolean
5660
): Def.Initialize[InputTask[A]] = Def.inputTaskDyn {
5761
val task = input.parsed
5862
Def.taskIf {
Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import ConditionalKeys._
2+
import com.typesafe.tools.mima.plugin.MimaKeys.mimaPreviousArtifacts
3+
import explicitdeps.ExplicitDepsPlugin
24
import explicitdeps.ExplicitDepsPlugin.autoImport._
35
import sbt.Keys._
46
import sbt.ScriptedPlugin.autoImport.scripted
7+
import sbt._
58
import sbt.plugins.SbtPlugin
6-
import sbt.{Def, _}
9+
import sbtversionpolicy.SbtVersionPolicyMima
710

811
// This is all the crazy hacks to get cross compiling working with an sub-project that is an sbt plugin.
912
object SbtPluginSubProjectPlugin extends AutoPlugin {
1013

1114
override def trigger: PluginTrigger = allRequirements
12-
override def requires: Plugins = SbtPlugin
15+
override def requires: Plugins = SbtPlugin && SbtVersionPolicyMima && ExplicitDepsPlugin
1316

1417
object autoImport {
15-
val spspIsSbtCompatibleScalaVersion = settingKey[Boolean]("Checks if the current Scala version is 2.13")
18+
val spspCanBuild = settingKey[Boolean]("Checks if the project dependencies are using a compatible Scala version.")
1619
}
1720

1821
import autoImport._
@@ -21,29 +24,35 @@ object SbtPluginSubProjectPlugin extends AutoPlugin {
2124
List(
2225
crossScalaVersions := Nil,
2326
// Remove all library dependencies for Scala 2.13 as they will not resolve when cross building.
24-
libraryDependencies := settingDefaultIfSetting(libraryDependencies, scalaVersion, isScala213, Nil).value,
27+
// libraryDependencies := defaultIfCannotBuild(libraryDependencies, Nil).value,
2528
// Remove all project dependencies for Scala 2.13 as they will not resolve when cross building.
2629
projectDependencies := taskDefaultIfSkipped(projectDependencies, Nil).value,
2730
scripted := inputDefaultIfSkipped(scripted, ()).evaluated,
28-
spspIsSbtCompatibleScalaVersion := isSbtCompatibleScalaVersionSetting.value,
31+
spspCanBuild := canBuildSetting.value,
2932
// We can't skip this as it has to run at least once or sbt complains.
3033
update / skip := false,
3134
// Skip everything else otherwise it will just fail.
32-
skip := !spspIsSbtCompatibleScalaVersion.value,
33-
undeclaredCompileDependenciesFilter -= moduleFilter()
35+
skip := !spspCanBuild.value,
36+
undeclaredCompileDependenciesFilter -= moduleFilter(),
37+
mimaPreviousArtifacts := defaultIfCannotBuild(mimaPreviousArtifacts, Set.empty[ModuleID]).value
3438
)
3539

36-
private def isSbtCompatibleScalaVersionSetting = Def.setting {
37-
if (isScala213(scalaVersion.value))
38-
throw new IllegalStateException("sbt project must not use Scala 2.13. Did you force the version with '+'?")
40+
def defaultIfCannotBuild[A](setting: Def.Initialize[A], default: => A): Def.Initialize[A] =
41+
settingDefaultIfSetting(setting, spspCanBuild, default)(!_)
42+
43+
private def canBuildSetting = Def.setting {
44+
if (!isScala212(scalaVersion.value))
45+
throw new IllegalStateException(
46+
"sbt project must use Scala 2.12. Check that you have not forced the version with '+'."
47+
)
3948
val versions =
4049
scalaVersion.all(ScopeFilter(inDependencies(ThisProject, transitive = true, includeRoot = false))).value
41-
!versions.exists(isScala213)
50+
versions.forall(isScala212)
4251
}
4352

44-
private def isScala213(version: String) =
53+
private def isScala212(version: String) =
4554
CrossVersion.partialVersion(version) match {
46-
case Some((2, n)) if n == 13 => true
55+
case Some((2, n)) if n == 12 => true
4756
case _ => false
4857
}
4958
}

0 commit comments

Comments
 (0)