Skip to content

Commit 50acf94

Browse files
committed
cross-build to sbt 2.x
1 parent d2c99b3 commit 50acf94

File tree

8 files changed

+78
-46
lines changed

8 files changed

+78
-46
lines changed

.github/workflows/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
with:
1515
jvm: temurin:8
1616
- run: rm -rf src/sbt-test/skip-sbt1.4
17-
- run: sbt test scripted
17+
- run: sbt +test +scripted
1818
jdk11:
1919
name: JDK11 tests
2020
runs-on: ubuntu-latest
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
jvm: temurin:11
2626
- run: rm -rf src/sbt-test/skip-sbt1.4
27-
- run: sbt test scripted
27+
- run: sbt +test +scripted
2828
jdk17:
2929
name: JDK17 tests
3030
runs-on: ubuntu-latest
@@ -35,7 +35,7 @@ jobs:
3535
jvm: temurin:17
3636
- run: rm -rf src/sbt-test/skip-java17+
3737
- run: rm -rf src/sbt-test/skip-sbt1.4
38-
- run: sbt test scripted
38+
- run: sbt +test +scripted
3939

4040
jdk21:
4141
name: JDK21 tests
@@ -46,7 +46,7 @@ jobs:
4646
with:
4747
jvm: temurin:21
4848
- run: rm -rf src/sbt-test/skip-java17+
49-
- run: sbt test scripted
49+
- run: sbt +test +scripted
5050
windows:
5151
name: Windows tests
5252
runs-on: windows-latest
@@ -55,7 +55,7 @@ jobs:
5555
- uses: coursier/setup-action@v1
5656
- run: rm -r -fo src\sbt-test\skip-sbt1.4
5757
- run: rm -r -fo src\sbt-test\skip-windows
58-
- run: sbt test-skip-windows scripted
58+
- run: sbt +"testOnly -- -l SkipWindows" +scripted
5959
shell: bash
6060
checks:
6161
name: Scalafmt

.github/workflows/release.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v4
1111
- uses: coursier/setup-action@v1
12+
with:
13+
jvm: temurin:8
1214
- uses: olafurpg/setup-gpg@v3
1315
- run: git fetch --unshallow
1416
- name: Publish ${{ github.ref }}

bin/test-release.sh

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ version=$1
66
cs resolve \
77
--sbt-version 1.0 \
88
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"
9+
10+
cs resolve \
11+
--sbt-version 2.0.0-M2 \
12+
--sbt-plugin "ch.epfl.scala:sbt-scalafix:$version"

build.sbt

+41-16
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ developers := List(
3131
)
3232
)
3333

34-
commands += Command.command("test-skip-windows") { s =>
35-
"testOnly -- -l SkipWindows" ::
36-
s
37-
}
38-
3934
// Dependencies
4035
resolvers ++= Resolver.sonatypeOssRepos("public")
4136
libraryDependencies ++= Dependencies.all
@@ -44,29 +39,59 @@ libraryDependencies ++= List(
4439
"org.scalatest" %% "scalatest" % "3.2.19" % Test
4540
)
4641

47-
scalaVersion := "2.12.20"
42+
lazy val scala212 = "2.12.20"
43+
lazy val scala3 = "3.3.4"
44+
45+
scalaVersion := scala212
46+
crossScalaVersions := Seq(scala212, scala3)
4847

4948
// keep this as low as possible to avoid running into binary incompatibility such as https://github.com/sbt/sbt/issues/5049
50-
pluginCrossBuild / sbtVersion := "1.4.0"
49+
pluginCrossBuild / sbtVersion := {
50+
scalaBinaryVersion.value match {
51+
case "2.12" =>
52+
"1.4.0"
53+
case _ =>
54+
"2.0.0-M2"
55+
}
56+
}
5157

5258
scriptedSbt := {
5359
val jdk = System.getProperty("java.specification.version").toDouble
5460

5561
if (jdk >= 21)
56-
"1.9.0" // first release that supports JDK21
62+
Ordering[String].max(
63+
(pluginCrossBuild / sbtVersion).value,
64+
"1.9.0" // first release that supports JDK21
65+
)
5766
else
5867
(pluginCrossBuild / sbtVersion).value
5968
}
6069

61-
libraryDependencies += compilerPlugin(scalafixSemanticdb)
62-
63-
scalacOptions ++= List("-Ywarn-unused", "-Yrangepos")
70+
libraryDependencies ++= {
71+
scalaBinaryVersion.value match {
72+
case "2.12" =>
73+
List(compilerPlugin(scalafixSemanticdb))
74+
case _ =>
75+
Nil
76+
}
77+
}
6478

65-
scalacOptions ++= List(
66-
"-target:jvm-1.8",
67-
"-Xfatal-warnings",
68-
"-Xlint"
69-
)
79+
scalacOptions ++= {
80+
scalaBinaryVersion.value match {
81+
case "2.12" =>
82+
List(
83+
"-Ywarn-unused",
84+
"-Yrangepos",
85+
"-Xfatal-warnings",
86+
"-Xlint"
87+
)
88+
case _ =>
89+
List(
90+
"-Wunused:all",
91+
"-Werror"
92+
)
93+
}
94+
}
7095

7196
// Scripted
7297
enablePlugins(ScriptedPlugin)

src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object Arg {
3838
.map(uri => java.nio.file.Paths.get(uri).toFile)
3939
.flatMap {
4040
case classDirectory if classDirectory.isDirectory =>
41-
classDirectory.**(RegularFileFilter).get
41+
classDirectory.**(RegularFileFilter).get()
4242
case jar =>
4343
Seq(jar)
4444
}
@@ -109,10 +109,10 @@ class ScalafixInterface private (
109109
scalafixArguments.run().toSeq
110110

111111
def availableRules(): Seq[ScalafixRule] =
112-
scalafixArguments.availableRules().asScala
112+
scalafixArguments.availableRules().asScala.toSeq
113113

114114
def rulesThatWillRun(): Seq[ScalafixRule] =
115-
try scalafixArguments.rulesThatWillRun().asScala
115+
try scalafixArguments.rulesThatWillRun().asScala.toSeq
116116
catch {
117117
case e: ScalafixException => throw new InvalidArgument(e.getMessage)
118118
}

src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SemanticRuleValidator(ifNotFound: SemanticdbNotFound) {
2525
invalidArguments.foreach { invalidArgument =>
2626
errors += invalidArgument.getMessage
2727
}
28-
errors
28+
errors.toSeq
2929
}
3030
}
3131
}

src/main/scala/scalafix/sbt/ScalafixEnable.scala

+15-15
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,21 @@ object ScalafixEnable {
155155
} else {
156156
val latestAvailable =
157157
tail.lastOption.getOrElse(earliestAvailable)
158-
Seq(
159-
semanticdbVersion := {
160-
val v = latestAvailable.toString
161-
sLog.value.info(
162-
s"Setting semanticdbVersion to $v in project " +
163-
s"${project.ref.project} since the version " +
164-
s"${recommendedSemanticdbV} tracked by scalafix " +
165-
s"${BuildInfo.scalafixVersion} is no longer " +
166-
s"published for scala " +
167-
s"${project.scalaVersion0.toString} - " +
168-
s"consider bumping scala"
169-
)
170-
v
171-
}
172-
)
158+
Seq(
159+
semanticdbVersion := {
160+
val v = latestAvailable.toString
161+
sLog.value.info(
162+
s"Setting semanticdbVersion to $v in project " +
163+
s"${project.ref.project} since the version " +
164+
s"${recommendedSemanticdbV} tracked by scalafix " +
165+
s"${BuildInfo.scalafixVersion} is no longer " +
166+
s"published for scala " +
167+
s"${project.scalaVersion0.toString} - " +
168+
s"consider bumping scala"
169+
)
170+
v
171+
}
172+
)
173173
}
174174
}
175175
} :+ (semanticdbEnabled := true)

src/main/scala/scalafix/sbt/ScalafixPlugin.scala

+7-6
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ object ScalafixPlugin extends AutoPlugin {
243243
}
244244

245245
update.result.value match {
246-
case Value(v) => v
246+
case Value(v: UpdateReport) => v
247247
case Inc(inc: Incomplete) =>
248248
Incomplete.allExceptions(inc).toList match {
249249
case (resolveException: ResolveException) :: Nil =>
@@ -264,7 +264,7 @@ object ScalafixPlugin extends AutoPlugin {
264264
}
265265
},
266266
ivyConfigurations += ScalafixConfig,
267-
scalafixAll := scalafixAllInputTask.evaluated,
267+
scalafixAll := scalafixAllInputTask().evaluated,
268268
(scalafixScalaBinaryVersion: @nowarn) :=
269269
scalaVersion.value.split('.').take(2).mkString(".")
270270
)
@@ -351,7 +351,7 @@ object ScalafixPlugin extends AutoPlugin {
351351
val invocationDepsExternal = parsed.map(_.dependency)
352352
val projectDepsInternal0 = projectDepsInternal.filter {
353353
case directory if directory.isDirectory =>
354-
directory.**(AllPassFilter).get.exists(_.isFile)
354+
directory.**(AllPassFilter).get().exists(_.isFile)
355355
case file if file.isFile => true
356356
case _ => false
357357
}
@@ -632,7 +632,7 @@ object ScalafixPlugin extends AutoPlugin {
632632
}
633633

634634
private lazy val checkIfTriggeredSectionExists: Boolean = {
635-
val confInArgs = interface.args
635+
val confInArgs: Option[Path] = interface.args
636636
.collect { case Arg.Config(conf) => conf }
637637
.flatten
638638
.lastOption
@@ -672,7 +672,7 @@ object ScalafixPlugin extends AutoPlugin {
672672
Tracked.diffInputs(
673673
streams.cacheDirectory / "targets-by-rule" / rule,
674674
cachingStyle
675-
)(targets) { changeReport: ChangeReport[File] =>
675+
)(targets) { (changeReport: ChangeReport[File]) =>
676676
doForStaleTargets(changeReport.modified -- changeReport.removed)
677677
}
678678

@@ -696,7 +696,8 @@ object ScalafixPlugin extends AutoPlugin {
696696
}
697697
}
698698

699-
val ruleTargetDiffs = interface.rulesThatWillRun
699+
val ruleTargetDiffs = interface
700+
.rulesThatWillRun()
700701
.map(rule => diffTargets(rule.name) _)
701702
.toList
702703
accumulateAndRunForStaleTargets(ruleTargetDiffs)

0 commit comments

Comments
 (0)