mirror of https://github.com/sbt/sbt.git
Replace previous scalafmt plugin by neo-scalafmt
The previous scalafmt plugin had two problems: * Caching with Coursier did not work correctly * It failed after the upgrade to 1.0 in my computer (from a clean fork): ``` [error] (testingProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (runProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (taskProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (stdTaskProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (actionsProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (protocolProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (commandProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (mainSettingsProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (mainProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (sbtProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (scriptedPluginProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] (scriptedSbtProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$ [error] Total time: 19 s, completed May 24, 2017 10:44:56 AM ``` This commit replaces the previous scalafmt integration by the one created by Lucidsoftware, big shoutout! (/cc @pauldraper) https://github.com/lucidsoftware/neo-sbt-scalafmt
This commit is contained in:
parent
e846f72ff3
commit
fd4bf0e635
|
|
@ -16,7 +16,7 @@ matrix:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
matrix:
|
matrix:
|
||||||
- SBT_CMD=";test:compile;scalafmtCheck;safeUnitTests;otherUnitTests"
|
- SBT_CMD=";test:compile;scalafmt::test;test:scalafmt::test;safeUnitTests;otherUnitTests"
|
||||||
# - SBT_CMD="mimaReportBinaryIssues"
|
# - SBT_CMD="mimaReportBinaryIssues"
|
||||||
- SBT_CMD="scripted actions/*"
|
- SBT_CMD="scripted actions/*"
|
||||||
- SBT_CMD="scripted apiinfo/* compiler-project/* ivy-deps-management/*"
|
- SBT_CMD="scripted apiinfo/* compiler-project/* ivy-deps-management/*"
|
||||||
|
|
|
||||||
44
build.sbt
44
build.sbt
|
|
@ -71,6 +71,7 @@ def testedBaseSettings: Seq[Setting[_]] =
|
||||||
|
|
||||||
lazy val sbtRoot: Project = (project in file("."))
|
lazy val sbtRoot: Project = (project in file("."))
|
||||||
.enablePlugins(ScriptedPlugin) // , SiteScaladocPlugin, GhpagesPlugin)
|
.enablePlugins(ScriptedPlugin) // , SiteScaladocPlugin, GhpagesPlugin)
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.configs(Sxr.sxrConf)
|
.configs(Sxr.sxrConf)
|
||||||
.aggregateSeq(nonRoots)
|
.aggregateSeq(nonRoots)
|
||||||
.settings(
|
.settings(
|
||||||
|
|
@ -107,6 +108,7 @@ lazy val bundledLauncherProj =
|
||||||
Release.launcherSettings(sbtLaunchJar)
|
Release.launcherSettings(sbtLaunchJar)
|
||||||
)
|
)
|
||||||
.enablePlugins(SbtLauncherPlugin)
|
.enablePlugins(SbtLauncherPlugin)
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.settings(
|
.settings(
|
||||||
name := "sbt-launch",
|
name := "sbt-launch",
|
||||||
moduleName := "sbt-launch",
|
moduleName := "sbt-launch",
|
||||||
|
|
@ -125,6 +127,7 @@ lazy val bundledLauncherProj =
|
||||||
// Runner for uniform test interface
|
// Runner for uniform test interface
|
||||||
lazy val testingProj = (project in file("testing"))
|
lazy val testingProj = (project in file("testing"))
|
||||||
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
|
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.dependsOn(testAgentProj)
|
.dependsOn(testAgentProj)
|
||||||
.settings(
|
.settings(
|
||||||
baseSettings,
|
baseSettings,
|
||||||
|
|
@ -138,17 +141,20 @@ lazy val testingProj = (project in file("testing"))
|
||||||
.configure(addSbtIO, addSbtCompilerClasspath, addSbtUtilLogging)
|
.configure(addSbtIO, addSbtCompilerClasspath, addSbtUtilLogging)
|
||||||
|
|
||||||
// Testing agent for running tests in a separate process.
|
// Testing agent for running tests in a separate process.
|
||||||
lazy val testAgentProj = (project in file("testing") / "agent").settings(
|
lazy val testAgentProj = (project in file("testing") / "agent")
|
||||||
minimalSettings,
|
.enablePlugins(ScalafmtPlugin)
|
||||||
crossScalaVersions := Seq(baseScalaVersion),
|
.settings(
|
||||||
crossPaths := false,
|
minimalSettings,
|
||||||
autoScalaLibrary := false,
|
crossScalaVersions := Seq(baseScalaVersion),
|
||||||
name := "Test Agent",
|
crossPaths := false,
|
||||||
libraryDependencies += testInterface
|
autoScalaLibrary := false,
|
||||||
)
|
name := "Test Agent",
|
||||||
|
libraryDependencies += testInterface
|
||||||
|
)
|
||||||
|
|
||||||
// Basic task engine
|
// Basic task engine
|
||||||
lazy val taskProj = (project in file("tasks"))
|
lazy val taskProj = (project in file("tasks"))
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
name := "Tasks"
|
name := "Tasks"
|
||||||
|
|
@ -157,6 +163,7 @@ lazy val taskProj = (project in file("tasks"))
|
||||||
|
|
||||||
// Standard task system. This provides map, flatMap, join, and more on top of the basic task model.
|
// Standard task system. This provides map, flatMap, join, and more on top of the basic task model.
|
||||||
lazy val stdTaskProj = (project in file("tasks-standard"))
|
lazy val stdTaskProj = (project in file("tasks-standard"))
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.dependsOn(taskProj % "compile;test->test")
|
.dependsOn(taskProj % "compile;test->test")
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
|
|
@ -167,7 +174,7 @@ lazy val stdTaskProj = (project in file("tasks-standard"))
|
||||||
|
|
||||||
// Embedded Scala code runner
|
// Embedded Scala code runner
|
||||||
lazy val runProj = (project in file("run"))
|
lazy val runProj = (project in file("run"))
|
||||||
.enablePlugins(ContrabandPlugin)
|
.enablePlugins(ContrabandPlugin, ScalafmtPlugin)
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
name := "Run",
|
name := "Run",
|
||||||
|
|
@ -178,6 +185,7 @@ lazy val runProj = (project in file("run"))
|
||||||
.configure(addSbtIO, addSbtUtilLogging, addSbtCompilerClasspath)
|
.configure(addSbtIO, addSbtUtilLogging, addSbtCompilerClasspath)
|
||||||
|
|
||||||
lazy val scriptedSbtProj = (project in scriptedPath / "sbt")
|
lazy val scriptedSbtProj = (project in scriptedPath / "sbt")
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.dependsOn(commandProj)
|
.dependsOn(commandProj)
|
||||||
.settings(
|
.settings(
|
||||||
baseSettings,
|
baseSettings,
|
||||||
|
|
@ -187,6 +195,7 @@ lazy val scriptedSbtProj = (project in scriptedPath / "sbt")
|
||||||
.configure(addSbtIO, addSbtUtilLogging, addSbtCompilerInterface, addSbtUtilScripted)
|
.configure(addSbtIO, addSbtUtilLogging, addSbtCompilerInterface, addSbtUtilScripted)
|
||||||
|
|
||||||
lazy val scriptedPluginProj = (project in scriptedPath / "plugin")
|
lazy val scriptedPluginProj = (project in scriptedPath / "plugin")
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.dependsOn(sbtProj)
|
.dependsOn(sbtProj)
|
||||||
.settings(
|
.settings(
|
||||||
baseSettings,
|
baseSettings,
|
||||||
|
|
@ -196,6 +205,7 @@ lazy val scriptedPluginProj = (project in scriptedPath / "plugin")
|
||||||
|
|
||||||
// Implementation and support code for defining actions.
|
// Implementation and support code for defining actions.
|
||||||
lazy val actionsProj = (project in file("main-actions"))
|
lazy val actionsProj = (project in file("main-actions"))
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.dependsOn(runProj, stdTaskProj, taskProj, testingProj)
|
.dependsOn(runProj, stdTaskProj, taskProj, testingProj)
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
|
|
@ -217,7 +227,7 @@ lazy val actionsProj = (project in file("main-actions"))
|
||||||
)
|
)
|
||||||
|
|
||||||
lazy val protocolProj = (project in file("protocol"))
|
lazy val protocolProj = (project in file("protocol"))
|
||||||
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
|
.enablePlugins(ContrabandPlugin, JsonCodecPlugin, ScalafmtPlugin)
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
name := "Protocol",
|
name := "Protocol",
|
||||||
|
|
@ -231,7 +241,7 @@ lazy val protocolProj = (project in file("protocol"))
|
||||||
|
|
||||||
// General command support and core commands not specific to a build system
|
// General command support and core commands not specific to a build system
|
||||||
lazy val commandProj = (project in file("main-command"))
|
lazy val commandProj = (project in file("main-command"))
|
||||||
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
|
.enablePlugins(ContrabandPlugin, JsonCodecPlugin, ScalafmtPlugin)
|
||||||
.dependsOn(protocolProj)
|
.dependsOn(protocolProj)
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
|
|
@ -252,6 +262,7 @@ lazy val commandProj = (project in file("main-command"))
|
||||||
// The core macro project defines the main logic of the DSL, abstracted
|
// The core macro project defines the main logic of the DSL, abstracted
|
||||||
// away from several sbt implementators (tasks, settings, et cetera).
|
// away from several sbt implementators (tasks, settings, et cetera).
|
||||||
lazy val coreMacrosProj = (project in file("core-macros"))
|
lazy val coreMacrosProj = (project in file("core-macros"))
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.settings(
|
.settings(
|
||||||
commonSettings,
|
commonSettings,
|
||||||
name := "Core Macros",
|
name := "Core Macros",
|
||||||
|
|
@ -279,6 +290,7 @@ lazy val generateToolboxClasspath = Def.task {
|
||||||
|
|
||||||
// Fixes scope=Scope for Setting (core defined in collectionProj) to define the settings system used in build definitions
|
// Fixes scope=Scope for Setting (core defined in collectionProj) to define the settings system used in build definitions
|
||||||
lazy val mainSettingsProj = (project in file("main-settings"))
|
lazy val mainSettingsProj = (project in file("main-settings"))
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.dependsOn(commandProj, stdTaskProj, coreMacrosProj)
|
.dependsOn(commandProj, stdTaskProj, coreMacrosProj)
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
|
|
@ -298,7 +310,7 @@ lazy val mainSettingsProj = (project in file("main-settings"))
|
||||||
|
|
||||||
// The main integration project for sbt. It brings all of the projects together, configures them, and provides for overriding conventions.
|
// The main integration project for sbt. It brings all of the projects together, configures them, and provides for overriding conventions.
|
||||||
lazy val mainProj = (project in file("main"))
|
lazy val mainProj = (project in file("main"))
|
||||||
.enablePlugins(ContrabandPlugin)
|
.enablePlugins(ContrabandPlugin, ScalafmtPlugin)
|
||||||
.dependsOn(actionsProj, mainSettingsProj, runProj, commandProj)
|
.dependsOn(actionsProj, mainSettingsProj, runProj, commandProj)
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
|
|
@ -319,6 +331,7 @@ lazy val mainProj = (project in file("main"))
|
||||||
// technically, we need a dependency on all of mainProj's dependencies, but we don't do that since this is strictly an integration project
|
// technically, we need a dependency on all of mainProj's dependencies, but we don't do that since this is strictly an integration project
|
||||||
// with the sole purpose of providing certain identifiers without qualification (with a package object)
|
// with the sole purpose of providing certain identifiers without qualification (with a package object)
|
||||||
lazy val sbtProj = (project in file("sbt"))
|
lazy val sbtProj = (project in file("sbt"))
|
||||||
|
.enablePlugins(ScalafmtPlugin)
|
||||||
.dependsOn(mainProj, scriptedSbtProj % "test->test")
|
.dependsOn(mainProj, scriptedSbtProj % "test->test")
|
||||||
.settings(
|
.settings(
|
||||||
baseSettings,
|
baseSettings,
|
||||||
|
|
@ -464,13 +477,6 @@ def customCommands: Seq[Setting[_]] = Seq(
|
||||||
otherUnitTests := {
|
otherUnitTests := {
|
||||||
test.all(otherProjects).value
|
test.all(otherProjects).value
|
||||||
},
|
},
|
||||||
commands += Command.command("scalafmtCheck") { state =>
|
|
||||||
sys.process.Process("git diff --name-only --exit-code").! match {
|
|
||||||
case 0 => // ok
|
|
||||||
case x => sys.error("git diff detected! Did you compile before committing?")
|
|
||||||
}
|
|
||||||
state
|
|
||||||
},
|
|
||||||
commands += Command.command("release-sbt-local") { state =>
|
commands += Command.command("release-sbt-local") { state =>
|
||||||
"clean" ::
|
"clean" ::
|
||||||
"so compile" ::
|
"so compile" ::
|
||||||
|
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
import org.scalafmt.cli.Cli
|
|
||||||
import org.scalafmt.sbt.ScalafmtPlugin
|
|
||||||
import sbt._
|
|
||||||
import sbt.Keys._
|
|
||||||
import sbt.internal.inc.Analysis
|
|
||||||
|
|
||||||
// Taken from https://github.com/akka/alpakka/blob/master/project/AutomateScalafmtPlugin.scala
|
|
||||||
object AutomateScalafmtPlugin extends AutoPlugin {
|
|
||||||
|
|
||||||
object autoImport {
|
|
||||||
def automateScalafmtFor(configurations: Configuration*): Seq[Setting[_]] =
|
|
||||||
configurations.flatMap { c =>
|
|
||||||
inConfig(c)(
|
|
||||||
Seq(
|
|
||||||
compileInputs.in(compile) := {
|
|
||||||
scalafmtInc.value
|
|
||||||
compileInputs.in(compile).value
|
|
||||||
},
|
|
||||||
sourceDirectories.in(scalafmtInc) := Seq(scalaSource.value),
|
|
||||||
scalafmtInc := {
|
|
||||||
val cache = streams.value.cacheStoreFactory / "scalafmt"
|
|
||||||
val include = includeFilter.in(scalafmtInc).value
|
|
||||||
val exclude = excludeFilter.in(scalafmtInc).value
|
|
||||||
val sources =
|
|
||||||
sourceDirectories
|
|
||||||
.in(scalafmtInc)
|
|
||||||
.value
|
|
||||||
.descendantsExcept(include, exclude)
|
|
||||||
.get
|
|
||||||
.toSet
|
|
||||||
def format(handler: Set[File] => Unit, msg: String) = {
|
|
||||||
def update(handler: Set[File] => Unit, msg: String)(in: ChangeReport[File],
|
|
||||||
out: ChangeReport[File]) = {
|
|
||||||
val label = Reference.display(thisProjectRef.value)
|
|
||||||
val files = in.modified -- in.removed
|
|
||||||
Analysis
|
|
||||||
.counted("Scala source", "", "s", files.size)
|
|
||||||
.foreach(count => streams.value.log.info(s"$msg $count in $label ..."))
|
|
||||||
handler(files)
|
|
||||||
files
|
|
||||||
}
|
|
||||||
FileFunction.cached(cache, FilesInfo.hash, FilesInfo.exists)(update(handler, msg))(
|
|
||||||
sources
|
|
||||||
)
|
|
||||||
}
|
|
||||||
def formattingHandler(files: Set[File]) =
|
|
||||||
if (files.nonEmpty) {
|
|
||||||
val filesArg = files.map(_.getAbsolutePath).mkString(",")
|
|
||||||
Cli.main(Array("--quiet", "-i", "-f", filesArg))
|
|
||||||
}
|
|
||||||
format(formattingHandler, "Formatting")
|
|
||||||
format(_ => (), "Reformatted") // Recalculate the cache
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val scalafmtInc = taskKey[Unit]("Incrementally format modified sources")
|
|
||||||
|
|
||||||
override def requires = ScalafmtPlugin
|
|
||||||
|
|
||||||
override def trigger = allRequirements
|
|
||||||
|
|
||||||
override def projectSettings =
|
|
||||||
(includeFilter.in(scalafmtInc) := "*.scala") +: autoImport.automateScalafmtFor(Compile, Test)
|
|
||||||
}
|
|
||||||
|
|
@ -5,7 +5,8 @@ scalacOptions ++= Seq("-feature", "-language:postfixOps")
|
||||||
// addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.0")
|
// addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.0")
|
||||||
// addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.2")
|
// addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.2")
|
||||||
// addSbtPlugin("com.typesafe.sbt" % "sbt-javaversioncheck" % "0.1.0")
|
// addSbtPlugin("com.typesafe.sbt" % "sbt-javaversioncheck" % "0.1.0")
|
||||||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.7.0-RC1")
|
//addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.7.0-RC1")
|
||||||
|
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "0.3")
|
||||||
// addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.2.0")
|
// addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.2.0")
|
||||||
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.4.0")
|
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.4.0")
|
||||||
addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.0-M5")
|
addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.0-M5")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue