-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sbt
142 lines (128 loc) · 4.59 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Global / onChangedBuildSource := ReloadOnSourceChanges
val scala212 = "2.12.10"
ThisBuild / version := "0.3.2-SNAPSHOT"
val comp = "compile->compile"
def commonSettings: SettingsDefinition =
Def.settings(
scalaVersion in ThisBuild := scala212,
organization := "com.swoval",
homepage := Some(url("https://github.com/swoval/sbt-source-format")),
scmInfo := Some(
ScmInfo(
url("https://github.com/swoval/sbt-source-format"),
"[email protected]:swoval/sbt-source-format.git"
)
),
developers := List(
Developer(
"username",
"Ethan Atkins",
url("https://github.com/eatkins")
)
),
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")),
scalacOptions ++= Seq("-feature"),
publishTo := {
val p = publishTo.value
if (sys.props.get("SonatypeSnapshot").fold(false)(_ == "true"))
Some(Opts.resolver.sonatypeSnapshots): Option[Resolver]
else if (sys.props.get("SonatypeStaging").fold(false)(_ == "true"))
Some(Opts.resolver.sonatypeStaging): Option[Resolver]
else p
}
)
val lib = project.settings(
commonSettings,
libraryDependencies += "org.scala-sbt" % "sbt" % "1.3.0",
crossScalaVersions := Seq(scala212),
name := "sbt-source-format-lib",
)
def pluginSettings: Seq[Def.Setting[_]] = Def.settings(
commonSettings,
exportJars := true,
scripted := scripted.dependsOn(lib / publishLocal).evaluated,
dependencyOverrides := "org.scala-sbt" % "sbt" % "1.3.0" :: Nil,
scriptedBufferLog := false,
sbtVersion in pluginCrossBuild := "1.3.0",
crossSbtVersions := Seq("1.3.0"),
crossScalaVersions := Seq(scala212),
)
val global = project
.enablePlugins(SbtPlugin)
.settings(
pluginSettings,
name := "sbt-source-format-global",
description := "Adds global keys for formatting.",
)
.dependsOn(lib % comp)
val clangformat = project
.enablePlugins(SbtPlugin)
.settings(
pluginSettings,
name := "sbt-clang-format",
description := "Format source files using clang-format.",
)
.dependsOn(lib % comp, global % comp)
val javaformat = project
.enablePlugins(SbtPlugin)
.settings(
pluginSettings,
libraryDependencies += "com.google.googlejavaformat" % "google-java-format" % "1.6",
name := "sbt-java-format",
description := "Format source files using javaformat.",
)
.dependsOn(lib % comp, global % comp)
val scalaformat = project
.enablePlugins(SbtPlugin)
.settings(
pluginSettings,
Compile / javacOptions += "-Xlint:deprecation",
libraryDependencies += "org.scalameta" % "scalafmt-interfaces" % "2.3.2",
libraryDependencies += "io.get-coursier" %% "coursier" % "2.0.0-RC5-6",
name := "sbt-scala-format",
description := "Format source files using scalafmt.",
)
.dependsOn(lib % comp, global % comp)
val jvmformat = project
.enablePlugins(SbtPlugin)
.settings(
pluginSettings,
name := "sbt-jvm-format",
description := "Format jvm source files using scalafmt and javafmt.",
)
.dependsOn(lib % comp, javaformat % comp, scalaformat % comp, global % comp)
// The root project aggregates the library and three plugins via depends on
val `sbt-source-format` = (project in file("."))
.enablePlugins(SbtPlugin)
.settings(
pluginSettings,
scripted := scripted
.dependsOn(clangformat / publishLocal, javaformat / publishLocal, scalaformat / publishLocal)
.evaluated,
aggregate in publish := false,
name := "sbt-source-format",
description := "Format source files using clang-format, scalafmt and the google java format library.",
)
.dependsOn(lib % comp, clangformat % comp, jvmformat % comp, global % comp)
.aggregate(lib, clangformat, javaformat, jvmformat, scalaformat, global)
def release(local: Boolean): Def.Initialize[Task[Seq[Unit]]] = Def.taskDyn {
val _ = (
(`sbt-source-format` / Compile / scalafmtCheck).value,
(`sbt-source-format` / Test / scalafmtCheck).value,
)
val versions =
Seq(lib / version, clangformat / version, javaformat / version, scalaformat / version).join
val publishKey = if (local) publishLocal else publish
Def.taskDyn {
val v = (ThisBuild / version).value
val msg = s"Version $v was ${if (local) "not" else ""} a snapshot version"
assert(v.endsWith("-SNAPSHOT") == local, msg)
assert(versions.value.forall(_ == v))
Seq(lib, clangformat, javaformat, jvmformat, global, scalaformat, `sbt-source-format`)
.map(_ / publishKey)
.join
}
}
TaskKey[Unit]("release") := release(local = false).value
TaskKey[Unit]("releaseLocal") := release(local = true).value