-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathbuild.sbt
More file actions
380 lines (325 loc) · 14.2 KB
/
Copy pathbuild.sbt
File metadata and controls
380 lines (325 loc) · 14.2 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import sbt.Keys.{licenses, _}
import sbt._
logLevel := Level.Debug
// this values should be in sync with ergo-wallet/build.sbt
val scala211 = "2.11.12"
val scala212 = "2.12.20"
val scala213 = "2.13.18"
lazy val commonSettings = Seq(
organization := "org.ergoplatform",
name := "ergo",
scalaVersion := scala212,
// version is set via git tag vX.Y.Z:
// $ git tag v3.2.0
// $ git push origin v3.2.0
// without the tag version resolves to [branch name]-[git commit hash]-SNAPSHOT
// don't set the version manually
resolvers ++= Seq("Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/",
"SonaType" at "https://oss.sonatype.org/content/groups/public",
"Repo for leveldbjni-all" at "https://gitlab.com/api/v4/projects/61211221/packages/maven",
"Typesafe maven releases" at "https://dl.bintray.com/typesafe/maven-releases/",
"Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"),
homepage := Some(url("http://ergoplatform.org/")),
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),
publishTo := {
val centralSnapshots = "https://central.sonatype.com/repository/maven-snapshots/"
if (isSnapshot.value) Some("central-snapshots" at centralSnapshots)
else localStaging.value
},
scmInfo := Some(
ScmInfo(
url("https://github.com/ergoplatform/ergo"),
"scm:git@github.com:ergoplatform/ergo.git"
)
),
)
publishArtifact in (Compile, packageDoc) := false
val circeVersion = "0.14.15"
val akkaVersion = "2.6.10"
val akkaHttpVersion = "10.2.4"
val sigmaStateVersion = "6.0.6"
val ficusVersion = "1.4.7"
// for testing current sigmastate build (see sigmastate-ergo-it jenkins job)
val effectiveSigmaStateVersion = Option(System.getenv().get("SIGMASTATE_VERSION")).getOrElse(sigmaStateVersion)
val effectiveSigma = "org.scorexfoundation" %% "sigma-state" % effectiveSigmaStateVersion
libraryDependencies ++= Seq(
effectiveSigma.force()
.exclude("ch.qos.logback", "logback-classic")
.exclude("org.scorexfoundation", "scrypto"),
"ch.qos.logback" % "logback-classic" % "1.3.5",
// test dependencies
"org.scala-lang.modules" %% "scala-async" % "1.0.1" % "test",
"org.scalactic" %% "scalactic" % "3.0.3" % "test",
"org.scalatest" %% "scalatest" % "3.2.10" % "test,it",
"org.scalacheck" %% "scalacheck" % "1.14.+" % "test",
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % "test",
"org.asynchttpclient" % "async-http-client" % "2.6.+" % "test",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-properties" % "2.9.2" % "test",
"com.github.docker-java" % "docker-java-core" % "3.3.4" % Test,
"com.github.docker-java" % "docker-java-transport-httpclient5" % "3.3.4" % Test,
)
updateOptions := updateOptions.value.withLatestSnapshots(false)
fork := true
val opts = Seq(
"-server",
// JVM memory tuning for 2g ram
"-Xms128m",
"-Xmx2G",
//64M for stack, reduce after optimizations
"-Xss64m",
"-XX:+ExitOnOutOfMemoryError",
// Java 9 support
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-modules=java.xml.bind",
// from https://groups.google.com/d/msg/akka-user/9s4Yl7aEz3E/zfxmdc0cGQAJ
"-XX:+UseG1GC",
"-XX:+UseNUMA",
"-XX:+AlwaysPreTouch",
// probably can't use these with jstack and others tools
"-XX:+PerfDisableSharedMem",
"-XX:+ParallelRefProcEnabled",
"-XX:+UseStringDeduplication"
)
run / javaOptions ++= opts
scalacOptions ++= Seq("-Xasync")
scalacOptions --= Seq("-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Ywarn-unused:params", "-Xcheckinit")
val scalacOpts = Seq("-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Ywarn-unused:params", "-Xcheckinit")
Compile / sourceGenerators += Def.task {
val versionFile = (Compile / sourceManaged).value / "org" / "ergoplatform" / "Version.scala"
IO.write(versionFile,
s"""package org.ergoplatform
|
|object Version {
| val VersionString = "${version.value}"
|}
|""".stripMargin)
Seq(versionFile)
}
assembly / mainClass := Some("org.ergoplatform.ErgoApp")
assembly / test := {}
assembly / assemblyJarName := s"ergo-${version.value}.jar"
assembly / assemblyMergeStrategy := {
case "logback.xml" => MergeStrategy.last
case x if x.endsWith("module-info.class") => MergeStrategy.discard
case "reference.conf" => CustomMergeStrategy.concatReversed
case PathList("org", "bouncycastle", xs @ _*) => MergeStrategy.first
case PathList("org", "iq80", "leveldb", xs @ _*) => MergeStrategy.first
case PathList("org", "bouncycastle", xs @ _*) => MergeStrategy.first
case PathList("javax", "activation", xs @ _*) => MergeStrategy.last
case PathList("javax", "annotation", xs @ _*) => MergeStrategy.last
case other => (assembly / assemblyMergeStrategy).value(other)
}
enablePlugins(sbtdocker.DockerPlugin)
enablePlugins(JavaAppPackaging)
enablePlugins(ReproducibleBuildsPlugin)
Universal / mappings += {
val sampleFile = (Compile / resourceDirectory).value / "samples" / "local.conf.sample"
sampleFile -> "conf/local.conf"
}
// removes all jar mappings in universal and appends the fat jar
Universal / mappings ++= {
// universalMappings: Seq[(File,String)]
val universalMappings = (Universal / mappings).value
val fatJar = (Compile / assembly).value
// removing means filtering
val filtered = universalMappings filter {
case (_, name) => !name.endsWith(".jar")
}
// add the fat jar
filtered :+ (fatJar -> ("lib/" + fatJar.getName))
}
// add jvm parameter for typesafe config
bashScriptExtraDefines += """addJava "-Dconfig.file=${app_home}/../conf/local.conf""""
inConfig(Linux)(
Seq(
maintainer := "ergoplatform.org",
packageSummary := "Ergo node",
packageDescription := "Ergo node"
)
)
Defaults.itSettings
configs(IntegrationTest extend Test)
inConfig(IntegrationTest)(Seq(
// Run integration suites in parallel. Each suite is forked into its own JVM (testGrouping
// below) and the number running at once is bounded by the global Tags.ForkedTestGroup limit,
// so we get parallelism without exhausting host RAM (a suite can launch ~4 node containers).
parallelExecution := true,
testGrouping := {
val opts = forkOptions.value
definedTests.value.map { t =>
Tests.Group(name = t.name, tests = Seq(t), runPolicy = Tests.SubProcess(opts))
}
},
test := (test dependsOn docker).value,
scalacOptions ++= Seq("-Xasync")
))
// Cap how many forked test JVMs run concurrently. sbt's default
// concurrentRestrictions already contains Tags.limit(Tags.ForkedTestGroup, 1);
// simply += adds a second, looser rule and the strictest wins, so the
// 2-way parallelism would be a no-op. We replace the default rule by
// keeping the other defaults and setting ForkedTestGroup to 2.
Global / concurrentRestrictions := Seq(
Tags.limitAll(math.max(1, java.lang.Runtime.getRuntime.availableProcessors())),
Tags.limit(Tags.ForkedTestGroup, 2),
Tags.exclusiveGroup(Tags.Clean)
)
docker / dockerfile := {
val configDevNet = (IntegrationTest / resourceDirectory).value / "devnetTemplate.conf"
val configTestNet = (IntegrationTest / resourceDirectory).value / "testnetTemplate.conf"
val configMainNet = (IntegrationTest / resourceDirectory).value / "mainnetTemplate.conf"
new Dockerfile {
from("eclipse-temurin:11-jre-jammy")
label("ergo-integration-tests", "ergo-integration-tests")
add(assembly.value, "/opt/ergo/ergo.jar")
add(Seq(configDevNet), "/opt/ergo")
add(Seq(configTestNet), "/opt/ergo")
add(Seq(configMainNet), "/opt/ergo")
}
}
docker / buildOptions := BuildOptions(
removeIntermediateContainers = BuildOptions.Remove.OnSuccess
)
//Scapegoat settings
ThisBuild / scapegoatVersion := "1.3.11"
scapegoatDisabledInspections := Seq("FinalModifierOnCaseClass")
Test / testOptions := Seq(Tests.Filter(s => !s.endsWith("Bench")))
lazy val avldb = (project in file("avldb"))
.disablePlugins(ScapegoatSbtPlugin) // not compatible with crossScalaVersions
.settings(
crossScalaVersions := Seq(scala213, scalaVersion.value, scala211),
commonSettings,
name := "avldb",
// set bytecode version to 8 to fix NoSuchMethodError for various ByteBuffer methods
// see https://github.com/eclipse/jetty.project/issues/3244
// these options applied only in "compile" task since scalac crashes on scaladoc compilation with "-release 8"
// see https://github.com/scala/community-builds/issues/796#issuecomment-423395500
Compile / compile / scalacOptions ++= (if (scalaBinaryVersion.value == "2.11") Seq() else Seq("-release", "8")),
Compile / compile / scalacOptions --= scalacOpts,
Compile / compile / javacOptions ++= javacReleaseOption,
libraryDependencies ++= Seq(
// database dependencies
"org.ethereum" % "leveldbjni-all" % "1.18.3",
//the following pure-java leveldb implementation is needed only on specific platforms, such as 32-bit Raspberry Pi
//in future, it could be reasonable to have special builds with this Java db only, and for most of platforms use
//jni wrapper over native library included in leveldbjni-all
"org.iq80.leveldb" % "leveldb" % "0.12"
)
)
lazy val avldb_benchmarks = (project in file("avldb/benchmarks"))
.settings(
commonSettings,
name := "avldb-benchmarks",
libraryDependencies ++= Seq(
"com.storm-enroute" %% "scalameter" % "0.9" % "test"
),
publishArtifact := false,
resolvers ++= Seq("Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"),
testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
Test / parallelExecution := false,
logBuffered := false
)
.dependsOn(avldb)
.enablePlugins(JmhPlugin)
lazy val ergoCore = (project in file("ergo-core"))
.disablePlugins(ScapegoatSbtPlugin) // not compatible with crossScalaVersions
.dependsOn(avldb % "test->test;compile->compile")
.dependsOn(ergoWallet % "test->test;compile->compile")
.settings(
crossScalaVersions := Seq(scala213, scalaVersion.value, scala211),
commonSettings,
name := "ergo-core",
libraryDependencies ++= Seq(
"com.iheart" %% "ficus" % ficusVersion,
effectiveSigma,
(effectiveSigma % Test).classifier("tests")
),
Compile / compile / scalacOptions ++= (if (scalaBinaryVersion.value == "2.11") Seq() else Seq("-release", "8")),
Compile / compile / scalacOptions --= scalacOpts,
Test / parallelExecution := false,
)
lazy val ergoWallet = (project in file("ergo-wallet"))
.disablePlugins(ScapegoatSbtPlugin) // not compatible with crossScalaVersions
.settings(
crossScalaVersions := Seq(scala213, scalaVersion.value, scala211),
commonSettings,
name := "ergo-wallet",
libraryDependencies ++= Seq(
effectiveSigma,
(effectiveSigma % Test).classifier("tests")
),
Compile / compile / scalacOptions ++= (if(scalaBinaryVersion.value == "2.11")
Seq.empty
else
Seq("-release", "8")
),
)
lazy val It2Test = config("it2") extend (IntegrationTest, Test)
configs(It2Test)
inConfig(It2Test)(Defaults.testSettings ++ Seq(
parallelExecution := false,
test := (test dependsOn docker).value,
scalacOptions ++= Seq("-Xasync")
))
lazy val ergo = (project in file("."))
.settings(
commonSettings,
name := "ergo",
// set bytecode version to 8 to fix NoSuchMethodError for various ByteBuffer methods
// see https://github.com/eclipse/jetty.project/issues/3244
// these options applied only in "compile" task since scalac crashes on scaladoc compilation with "-release 8"
// see https://github.com/scala/community-builds/issues/796#issuecomment-423395500
Compile / compile / scalacOptions ++= Seq("-release", "8"),
Compile / compile / javacOptions ++= javacReleaseOption,
libraryDependencies ++= Seq(
// api dependencies
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
// network dependencies
"com.typesafe.akka" %% "akka-stream" % akkaVersion, // required for akka-http to compile
"com.typesafe.akka" %% "akka-actor" % akkaVersion, // required for akka-http to compile
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-parsing" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"org.bitlet" % "weupnp" % "0.1.4",
// command line args parsing
"com.github.scopt" %% "scopt" % "4.1.0",
// API dependencies
"de.heikoseeberger" %% "akka-http-circe" % "1.39.2",
// app dependencies
// jaxb-api is included only to avoid a runtime exception
"javax.xml.bind" % "jaxb-api" % "2.4.0-b180830.0359",
// caching
"com.github.ben-manes.caffeine" % "caffeine" % "2.9.3" // use 3.x only for java 11+
)
)
.dependsOn(ergoCore % "test->test;compile->compile")
.dependsOn(ergoWallet % "test->test;compile->compile")
.dependsOn(avldb % "test->test;compile->compile")
.configs(It2Test)
// PGP key for signing a release build published to sonatype
// signing is done by sbt-pgp plugin
// how to generate a key - https://central.sonatype.org/pages/working-with-pgp-signatures.html
// how to export a key and use it with Travis - https://docs.scala-lang.org/overviews/contributors/index.html#export-your-pgp-key-pair
pgpPublicRing := file("ci/pubring.asc")
pgpSecretRing := file("ci/secring.asc")
pgpPassphrase := sys.env.get("PGP_PASSPHRASE").map(_.toArray)
usePgpKeyHex("D78982639AD538EF361DEC6BF264D529385A0333")
credentials ++= (for {
username <- Option(System.getenv().get("SONATYPE_USERNAME"))
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)).toSeq
def javacReleaseOption = {
if (System.getProperty("java.version").startsWith("1."))
// java <9 "--release" is not supported
Seq()
else
Seq("--release", "8")
}
// prefix version with "-SNAPSHOT" for builds without a git tag
ThisBuild / dynverSonatypeSnapshots := true
// use "-" instead of default "+"
ThisBuild / dynverSeparator := "-"