-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sbt
217 lines (197 loc) · 6.64 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import sbtrelease.ReleaseStateTransformations._
import scala.collection.JavaConverters._
import java.lang.management.ManagementFactory
val Scala212 = "2.12.20"
val Scala213 = "2.13.16"
Global / onChangedBuildSource := ReloadOnSourceChanges
val unusedWarnings = Seq("-Ywarn-unused")
val tagName = Def.setting {
s"v${if (releaseUseGlobalVersion.value) (ThisBuild / version).value
else version.value}"
}
val tagOrHash = Def.setting {
if (isSnapshot.value)
sys.process.Process("git rev-parse HEAD").lineStream_!.head
else tagName.value
}
val scriptedSettings = Seq(
libraryDependencies := {
val libs = libraryDependencies.value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) =>
libs
case _ =>
libs.filterNot(_.organization == "org.scala-sbt")
}
},
sbtTestDirectory := file("test"),
scriptedBufferLog := false,
scriptedLaunchOpts ++= ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList
.filter(a => Seq("-Xmx", "-Xms", "-XX", "-Dsbt.log.noformat").exists(a.startsWith)),
scriptedLaunchOpts ++= Seq(
s"-Dprotoc-lint-version=${version.value}",
s"-Dprotoc-lint-artifact-id=${name.value}"
)
)
val cleanLocalMaven = "cleanLocalMaven"
TaskKey[Unit](cleanLocalMaven) := {
val dir = Path.userHome / s".m2/repository/${organization.value.replace('.', '/')}"
println("delete " + dir)
IO.delete(dir)
}
val commonSettings = Def.settings(
description := "protobuf linter",
licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
organization := "io.github.scalapb-json",
ReleasePlugin.extraReleaseCommands,
commands += Command.command("updateReadme")(UpdateReadme.updateReadmeTask),
releaseTagName := tagName.value,
releaseCrossBuild := true,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
UpdateReadme.updateReadmeProcess,
tagRelease,
releaseStepCommandAndRemaining("set ThisBuild / useSuperShell := false"),
releaseStepCommandAndRemaining("+ publishSigned"),
releaseStepCommandAndRemaining("set ThisBuild / useSuperShell := true"),
releaseStepCommand("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
UpdateReadme.updateReadmeProcess,
pushChanges
),
(Compile / doc / scalacOptions) ++= {
val t = tagOrHash.value
Seq(
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath,
"-doc-source-url",
s"https://github.com/scalapb-json/protoc-lint/tree/${t}€{FILE_PATH}.scala"
)
},
(Global / pomExtra) := {
<url>https://github.com/scalapb-json/protoc-lint</url>
<scm>
<connection>scm:git:github.com/scalapb-json/protoc-lint.git</connection>
<developerConnection>scm:git:[email protected]:scalapb-json/protoc-lint.git</developerConnection>
<url>https://github.com/scalapb-json/protoc-lint.git</url>
<tag>{tagOrHash.value}</tag>
</scm>
<developers>
<developer>
<id>xuwei-k</id>
<name>Kenji Yoshida</name>
<url>https://github.com/xuwei-k</url>
</developer>
</developers>
},
publishLocal := {}, // use local maven in scripted-test
publishTo := sonatypePublishToBundle.value,
scalaVersion := Scala212,
crossScalaVersions := Seq(Scala212),
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-Xlint",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions"
),
scalacOptions ++= PartialFunction
.condOpt(CrossVersion.partialVersion(scalaVersion.value)) {
case Some((2, v)) if v <= 12 => Seq("-Yno-adapted-args")
}
.toList
.flatten,
libraryDependencies += "com.thesamet.scalapb" %% "protoc-bridge" % "0.9.8",
scalacOptions ++= unusedWarnings,
Seq(Compile, Test).flatMap(c => c / console / scalacOptions --= unusedWarnings)
)
commonSettings
val noPublish = Seq(
publish / skip := true,
publishArtifact := false,
publish := {},
PgpKeys.publishSigned := {},
PgpKeys.publishLocalSigned := {}
)
noPublish
commands += Command.command("testAll") {
List(
cleanLocalMaven,
s"project ${shaded.id}",
"+ publishM2",
"scripted",
s"project ${protocLint.id}",
"+ publishM2",
"scripted",
"project /",
cleanLocalMaven
) ::: _
}
val argonautVersion = settingKey[String]("")
val protocLint = Project("protoc-lint", file("protoc-lint"))
.settings(
commonSettings,
crossScalaVersions := Seq(Scala212, Scala213),
scriptedSettings,
(Compile / unmanagedResources) += (LocalRootProject / baseDirectory).value / "LICENSE.txt",
name := UpdateReadme.projectName,
argonautVersion := "6.3.11",
libraryDependencies ++= Seq(
"com.google.protobuf" % "protobuf-java-util" % "3.25.5",
"io.github.argonaut-io" %% "argonaut" % argonautVersion.value
)
)
.enablePlugins(ScriptedPlugin)
val shadeTarget = settingKey[String]("Target to use when shading")
(ThisBuild / shadeTarget) := s"protoc_lint_shaded.v${version.value.replaceAll("[.-]", "_")}.@0"
val shaded = Project("shaded", file("shaded"))
.settings(
commonSettings,
scriptedSettings,
name := UpdateReadme.shadedName,
(assembly / assemblyShadeRules) := Seq(
ShadeRule.rename("com.google.**" -> shadeTarget.value).inAll,
ShadeRule.rename("play.api.libs.**" -> shadeTarget.value).inAll,
ShadeRule.rename("argonaut.**" -> shadeTarget.value).inAll
),
(assembly / assemblyExcludedJars) := {
val toInclude = Seq(
"gson",
"guava",
"argonaut",
"protobuf-java",
"protobuf-java-util"
)
(assembly / fullClasspath).value.filterNot { c => toInclude.exists(prefix => c.data.getName.startsWith(prefix)) }
},
(Compile / packageBin / artifact) := (Compile / assembly / artifact).value,
addArtifact(Compile / packageBin / artifact, assembly),
pomPostProcess := { node =>
import scala.xml.Comment
import scala.xml.Elem
import scala.xml.Node
import scala.xml.transform.RuleTransformer
import scala.xml.transform.RewriteRule
new RuleTransformer(new RewriteRule {
override def transform(node: Node) =
node match {
case e: Elem
if e.label == "dependency" && e.child
.exists(child => child.label == "artifactId" && child.text.startsWith(UpdateReadme.projectName)) =>
Comment(s"scalapb_lint has been removed.")
case _ =>
node
}
}).transform(node).head
}
)
.dependsOn(protocLint)
.enablePlugins(ScriptedPlugin)
val root = project.in(file(".")).aggregate(protocLint, shaded)