Skip to content

Commit f512f88

Browse files
xuwei-kkitbellew
authored andcommitted
add sbt 2.x cross build setting
1 parent 0344d19 commit f512f88

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- run:
2929
# for git tests
3030
git config --global user.email "[email protected]" && git config --global user.name "scalafmt"
31-
- run: sbt plugin/scripted
31+
- run: sbt plugin/scripted "++ 3.x" compile
3232

3333
formatting:
3434
runs-on: ubuntu-latest

build.sbt

+17-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ inThisBuild(List(
3434
),
3535
resolvers ++= Resolver.sonatypeOssRepos("public"),
3636
scalaVersion := "2.12.20",
37+
crossScalaVersions += "3.3.4",
3738
packageDoc / publishArtifact := insideCI.value,
3839
packageSrc / publishArtifact := insideCI.value,
3940
))
@@ -47,14 +48,27 @@ lazy val plugin = project.enablePlugins(SbtPlugin).settings(
4748
moduleName := "sbt-scalafmt",
4849
libraryDependencies ++= List(
4950
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
50-
"org.scalameta" %% "scalafmt-sysops" % scalafmtVersion,
51-
"org.scalameta" %% "scalafmt-dynamic" % scalafmtVersion,
51+
"org.scalameta" %% "scalafmt-sysops" % scalafmtVersion cross
52+
CrossVersion.for3Use2_13,
53+
"org.scalameta" %% "scalafmt-dynamic" % scalafmtVersion cross
54+
CrossVersion.for3Use2_13,
5255
),
5356
scriptedBufferLog := false,
5457
scriptedLaunchOpts += s"-Dplugin.version=${version.value}",
5558
// For compat reasons we have this in here to ensure we are testing against 1.2.8
5659
// We honestly probably don't need to, so if this ever causes issues, rip it out.
57-
pluginCrossBuild / sbtVersion := "1.2.8",
60+
pluginCrossBuild / sbtVersion := {
61+
scalaBinaryVersion.value match {
62+
case "2.12" => "1.2.8"
63+
case _ => "2.0.0-M2"
64+
}
65+
},
66+
conflictWarning := {
67+
scalaBinaryVersion.value match {
68+
case "3" => ConflictWarning("warn", Level.Warn, false)
69+
case _ => conflictWarning.value
70+
}
71+
},
5872
)
5973

6074
// For some reason, it doesn't work if this is defined in globalSettings in PublishPlugin.

plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import java.io.OutputStreamWriter
44
import java.nio.file.Path
55

66
import sbt.Keys._
7-
import sbt._
7+
// format: off
8+
import sbt.{given, _}
9+
// format: on
810
import sbt.librarymanagement.MavenRepository
911
import sbt.util.CacheImplicits._
1012
import sbt.util.CacheStoreFactory
@@ -396,8 +398,8 @@ object ScalafmtPlugin extends AutoPlugin {
396398
private def getScalafmtSourcesTask(
397399
f: (Seq[File], Seq[File], FormatSession) => InitTask,
398400
) = Def.taskDyn[Unit] {
399-
val sources = unmanagedSources.in(scalafmt).?.value.getOrElse(Seq.empty)
400-
val dirs = unmanagedSourceDirectories.in(scalafmt).?.value.getOrElse(Nil)
401+
val sources = (scalafmt / unmanagedSources).?.value.getOrElse(Seq.empty)
402+
val dirs = (scalafmt / unmanagedSourceDirectories).?.value.getOrElse(Nil)
401403
getScalafmtTask(f)(sources, dirs, scalaConfig.value)
402404
}
403405

@@ -462,10 +464,10 @@ object ScalafmtPlugin extends AutoPlugin {
462464
scalafmtCheck := getScalafmtSourcesTask(scalafmtCheckTask).value,
463465
scalafmtSbtCheck := getScalafmtSbtTasks(scalafmtSbtCheckTask).value,
464466
scalafmtDoFormatOnCompile := Def.settingDyn {
465-
if (scalafmtOnCompile.value) scalafmt.in(resolvedScoped.value.scope)
467+
if (scalafmtOnCompile.value) resolvedScoped.value.scope / scalafmt
466468
else Def.task(())
467469
}.value,
468-
sources.in(Compile) := sources.in(Compile)
470+
Compile / sources := (Compile / sources)
469471
.dependsOn(scalafmtDoFormatOnCompile).value,
470472
scalafmtOnly := {
471473
val files = spaceDelimited("<files>").parsed
@@ -509,7 +511,7 @@ object ScalafmtPlugin extends AutoPlugin {
509511
)
510512

511513
override def buildSettings: Seq[Def.Setting[_]] =
512-
Seq(scalafmtConfig := baseDirectory.in(ThisBuild).value / ".scalafmt.conf")
514+
Seq(scalafmtConfig := (ThisBuild / baseDirectory).value / ".scalafmt.conf")
513515

514516
override def globalSettings: Seq[Def.Setting[_]] = Seq(
515517
scalafmtFilter := "",

0 commit comments

Comments
 (0)