diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54527eb..07b222e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - run: # for git tests git config --global user.email "scalafmt@scalameta.org" && git config --global user.name "scalafmt" - - run: sbt plugin/scripted + - run: sbt plugin/scripted "++ 3.x" compile formatting: runs-on: ubuntu-latest diff --git a/build.sbt b/build.sbt index f42c202..4e89452 100644 --- a/build.sbt +++ b/build.sbt @@ -34,6 +34,7 @@ inThisBuild(List( ), resolvers ++= Resolver.sonatypeOssRepos("public"), scalaVersion := "2.12.20", + crossScalaVersions += "3.3.4", packageDoc / publishArtifact := insideCI.value, packageSrc / publishArtifact := insideCI.value, )) @@ -47,14 +48,27 @@ lazy val plugin = project.enablePlugins(SbtPlugin).settings( moduleName := "sbt-scalafmt", libraryDependencies ++= List( "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0", - "org.scalameta" %% "scalafmt-sysops" % scalafmtVersion, - "org.scalameta" %% "scalafmt-dynamic" % scalafmtVersion, + "org.scalameta" %% "scalafmt-sysops" % scalafmtVersion cross + CrossVersion.for3Use2_13, + "org.scalameta" %% "scalafmt-dynamic" % scalafmtVersion cross + CrossVersion.for3Use2_13, ), scriptedBufferLog := false, scriptedLaunchOpts += s"-Dplugin.version=${version.value}", // For compat reasons we have this in here to ensure we are testing against 1.2.8 // We honestly probably don't need to, so if this ever causes issues, rip it out. - pluginCrossBuild / sbtVersion := "1.2.8", + pluginCrossBuild / sbtVersion := { + scalaBinaryVersion.value match { + case "2.12" => "1.2.8" + case _ => "2.0.0-M2" + } + }, + conflictWarning := { + scalaBinaryVersion.value match { + case "3" => ConflictWarning("warn", Level.Warn, false) + case _ => conflictWarning.value + } + }, ) // For some reason, it doesn't work if this is defined in globalSettings in PublishPlugin. diff --git a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala index 5160f6b..fe6b313 100644 --- a/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala +++ b/plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala @@ -4,7 +4,9 @@ import java.io.OutputStreamWriter import java.nio.file.Path import sbt.Keys._ -import sbt._ +// format: off +import sbt.{given, _} +// format: on import sbt.librarymanagement.MavenRepository import sbt.util.CacheImplicits._ import sbt.util.CacheStoreFactory @@ -396,8 +398,8 @@ object ScalafmtPlugin extends AutoPlugin { private def getScalafmtSourcesTask( f: (Seq[File], Seq[File], FormatSession) => InitTask, ) = Def.taskDyn[Unit] { - val sources = unmanagedSources.in(scalafmt).?.value.getOrElse(Seq.empty) - val dirs = unmanagedSourceDirectories.in(scalafmt).?.value.getOrElse(Nil) + val sources = (scalafmt / unmanagedSources).?.value.getOrElse(Seq.empty) + val dirs = (scalafmt / unmanagedSourceDirectories).?.value.getOrElse(Nil) getScalafmtTask(f)(sources, dirs, scalaConfig.value) } @@ -462,10 +464,10 @@ object ScalafmtPlugin extends AutoPlugin { scalafmtCheck := getScalafmtSourcesTask(scalafmtCheckTask).value, scalafmtSbtCheck := getScalafmtSbtTasks(scalafmtSbtCheckTask).value, scalafmtDoFormatOnCompile := Def.settingDyn { - if (scalafmtOnCompile.value) scalafmt.in(resolvedScoped.value.scope) + if (scalafmtOnCompile.value) resolvedScoped.value.scope / scalafmt else Def.task(()) }.value, - sources.in(Compile) := sources.in(Compile) + Compile / sources := (Compile / sources) .dependsOn(scalafmtDoFormatOnCompile).value, scalafmtOnly := { val files = spaceDelimited("").parsed @@ -509,7 +511,7 @@ object ScalafmtPlugin extends AutoPlugin { ) override def buildSettings: Seq[Def.Setting[_]] = - Seq(scalafmtConfig := baseDirectory.in(ThisBuild).value / ".scalafmt.conf") + Seq(scalafmtConfig := (ThisBuild / baseDirectory).value / ".scalafmt.conf") override def globalSettings: Seq[Def.Setting[_]] = Seq( scalafmtFilter := "",