-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sbt
295 lines (270 loc) · 12.1 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
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
resolvers ++= Resolver.sonatypeOssRepos("public")
resolvers ++= Resolver.sonatypeOssRepos("snapshots")
inThisBuild(
Seq(
scalaVersion := "3.3.3", // Also update docs/publishWebsite.sh and any ref to scala-3.3.3
)
)
/** Versions */
lazy val V = new {
val scalaDID = "0.1.0-M19"
// FIXME another bug in the test framework https://github.com/scalameta/munit/issues/554
val munit = "1.0.0" // "0.7.29"
// // https://mvnrepository.com/artifact/org.scala-js/scalajs-dom
// // val scalajsLogging = "1.1.2-SNAPSHOT" //"1.1.2"
// // https://mvnrepository.com/artifact/dev.zio/zio
val zio = "2.1.5"
val zioJson = "0.7.1"
// val zioMunitTest = "0.1.1"
val zioHttp = "3.0.0-RC6"
val zioConfig = "4.0.1"
val zioLogging = "2.2.4"
val zioSl4j = "2.2.2"
val logback = "1.5.6"
val logstash = "7.4"
val jansi = "2.4.1"
val mongo = "1.1.0-RC10"
val embedMongo = "4.14.0"
val munitZio = "0.1.1"
val zioTest = "2.1.5"
val zioTestSbt = "2.1.5"
val zioTestMagnolia = "2.1.5"
// For WEBAPP
val laminar = "17.0.0"
val waypoint = "7.0.0"
val upickle = "3.3.1"
// https://www.npmjs.com/package/material-components-web
val materialComponents = "12.0.0"
}
/** Dependencies */
lazy val D = new {
val scalaDID = Def.setting("app.fmgp" %%% "did" % V.scalaDID)
val scalaDID_imp = Def.setting("app.fmgp" %%% "did-imp" % V.scalaDID)
val scalaDID_peer = Def.setting("app.fmgp" %%% "did-method-peer" % V.scalaDID)
val scalaDID_framework = Def.setting("app.fmgp" %%% "did-framework" % V.scalaDID)
// /** The [[java.security.SecureRandom]] is used by the [[java.util.UUID.randomUUID()]] method in [[MsgId]].
// *
// * See more https://github.com/scala-js/scala-js-java-securerandom
// */
// val scalajsJavaSecureRandom = Def.setting(
// ("org.scala-js" %%% "scalajs-java-securerandom" % V.scalajsJavaSecureRandom)
// .cross(CrossVersion.for3Use2_13)
// )
val zio = Def.setting("dev.zio" %%% "zio" % V.zio)
// val zioStreams = Def.setting("dev.zio" %%% "zio-streams" % V.zio)
val zioJson = Def.setting("dev.zio" %%% "zio-json" % V.zioJson)
val zioHttp = Def.setting("dev.zio" %% "zio-http" % V.zioHttp)
val zioConfig = Def.setting("dev.zio" %% "zio-config" % V.zioConfig)
val zioConfigMagnolia = Def.setting("dev.zio" %% "zio-config-magnolia" % V.zioConfig) // For deriveConfig
val zioConfigTypesafe = Def.setting("dev.zio" %% "zio-config-typesafe" % V.zioConfig) // For HOCON
val zioLogging = Def.setting("dev.zio" %% "zio-logging" % V.zioLogging)
val zioLoggingSl4j = Def.setting("dev.zio" %% "zio-logging-slf4j" % V.zioSl4j)
val logback = Def.setting("ch.qos.logback" % "logback-classic" % V.logback)
val logstash = Def.setting("net.logstash.logback" % "logstash-logback-encoder" % V.logstash)
val jansi = Def.setting("org.fusesource.jansi" % "jansi" % V.jansi)
val mongo = Def.setting("org.reactivemongo" %% "reactivemongo" % V.mongo)
// // For munit https://scalameta.org/munit/docs/getting-started.html#scalajs-setup
val munit = Def.setting("org.scalameta" %%% "munit" % V.munit % Test)
val embedMongo = Def.setting("de.flapdoodle.embed" % "de.flapdoodle.embed.mongo" % V.embedMongo % Test)
// For munit zio https://github.com/poslegm/munit-zio
val munitZio = Def.setting("com.github.poslegm" %% "munit-zio" % V.munitZio % Test)
val zioTest = Def.setting("dev.zio" %% "zio-test" % V.zioTest % Test)
val zioTestSbt = Def.setting("dev.zio" %% "zio-test-sbt" % V.zioTestSbt % Test)
val zioTestMagnolia = Def.setting("dev.zio" %% "zio-test-magnolia" % V.zioTestMagnolia % Test)
// For WEBAPP
val laminar = Def.setting("com.raquo" %%% "laminar" % V.laminar)
val waypoint = Def.setting("com.raquo" %%% "waypoint" % V.waypoint)
val upickle = Def.setting("com.lihaoyi" %%% "upickle" % V.upickle)
}
/** NPM Dependencies */
lazy val NPM = new {
val qrcode = Seq("qrcode-generator" -> "1.4.4")
val materialDesign = Seq("material-components-web" -> V.materialComponents)
val sha256 = Seq("js-sha256" -> "0.9.0")
}
lazy val ENV = new {
val keyAgreementD = "Z6D8LduZgZ6LnrOHPrMTS6uU2u5Btsrk1SGs4fn8M7c"
val keyAgreementX = "Sr4SkIskjN_VdKTn0zkjYbhGTWArdUNE4j_DmUpnQGw"
val keyAuthenticationD = "INXCnxFEl0atLIIQYruHzGd5sUivMRyQOzu87qVerug"
val keyAuthenticationX = "MBjnXZxkMcoQVVL21hahWAw43RuAG-i64ipbeKKqwoA"
val envVars = Map(
"KEY_AGREEMENT_D" -> keyAgreementD,
"KEY_AGREEMENT_X" -> keyAgreementX,
"KEY_AUTHENTICATION_D" -> keyAuthenticationD,
"KEY_AUTHENTICATION_X" -> keyAuthenticationX
)
}
inThisBuild(
Seq(
scalacOptions ++= Seq(
// ### https://docs.scala-lang.org/scala3/guides/migration/options-new.html
// ### https://docs.scala-lang.org/scala3/guides/migration/options-lookup.html
//
"-encoding", // if an option takes an arg, supply it on the same line
"UTF-8", // source files are in UTF-8
"-deprecation", // warn about use of deprecated APIs
"-unchecked", // warn about unchecked type parameters
"-feature", // warn about misused language features (Note we are using 'language:implicitConversions')
"-Xfatal-warnings",
// TODO "-Yexplicit-nulls",
// "-Ysafe-init", // https://dotty.epfl.ch/docs/reference/other-new-features/safe-initialization.html
"-language:implicitConversions", // we can use with the flag '-feature'
// NO NEED ATM "-language:reflectiveCalls",
// "-Xprint-diff",
// "-Xprint-diff-del",
// "-Xprint-inline",
// NO NEED ATM "-Xsemanticdb"
// NO NEED ATM "-Ykind-projector"
),
// ### commonSettings ###
// Compile / doc / sources := Nil,
// ### setupTestConfig ### //lazy val settingsFlags: Seq[sbt.Def.SettingsDefinition] = ???
// libraryDependencies += D.munit.value, // BUG? "JS's Tests does not stop"
)
)
lazy val setupTestConfig: Seq[sbt.Def.SettingsDefinition] = Seq(
libraryDependencies += D.munit.value,
)
lazy val scalaJSBundlerConfigure: Project => Project =
_.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalaJSBundlerPlugin)
.settings(
scalaJSLinkerConfig ~= {
_.withSourceMap(false) // disabled because it somehow triggers warnings and errors
.withModuleKind(ModuleKind.CommonJSModule) // ModuleKind.ESModule
// must be set to ModuleKind.CommonJSModule in projects where ScalaJSBundler plugin is enabled
// .withJSHeader(
// """/* FMGP scala-did examples and tool
// | * https://github.com/FabioPinheiro/scala-did
// | * Copyright: Fabio Pinheiro - fabiomgpinheiro@gmail.com
// | */""".stripMargin.trim() + "\n"
// )
}
)
// .settings( //TODO https://scalacenter.github.io/scalajs-bundler/reference.html#jsdom
// //jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv(),
// //Test / requireJsDomEnv := true)
// )
.enablePlugins(ScalablyTypedConverterPlugin)
.settings(
// Compile / fastOptJS / webpackExtraArgs += "--mode=development",
// Compile / fullOptJS / webpackExtraArgs += "--mode=production",
Compile / fastOptJS / webpackDevServerExtraArgs += "--mode=development",
Compile / fullOptJS / webpackDevServerExtraArgs += "--mode=production",
useYarn := true
)
lazy val buildInfoConfigure: Project => Project = _.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoPackage := "org.hyperledger.identus.mediator",
buildInfoObject := "MediatorBuildInfo",
buildInfoKeys := Seq[BuildInfoKey](
name,
version,
scalaVersion,
sbtVersion,
// BuildInfoKey.action("buildTime") { System.currentTimeMillis }, // re-computed each time at compile
),
)
lazy val mediator = project
.in(file("mediator"))
.configure(buildInfoConfigure)
.settings(publish / skip := true)
.settings(
// FIX TODO (maybe the next version of the library will hide this compilation error)
// [error] -- Error: api/target/shaded/scala-3.2.2/src_managed/main/velocity/DefaultBSONHandlers.scala:379:2
// [error] undefined: new com.github.ghik.silencer.silent # -1: TermRef(TypeRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object com),object github),object ghik),object silencer),silent),<init>) at readTasty
// [error] one error found
// [error] (mediator / Compile / doc) DottyDoc Compilation Failed
Compile / doc / sources := Seq.empty
)
.settings((setupTestConfig): _*)
.settings(
libraryDependencies += D.scalaDID_imp.value,
libraryDependencies += D.scalaDID_peer.value,
libraryDependencies += D.scalaDID_framework.value,
libraryDependencies += D.zioHttp.value,
libraryDependencies ++= Seq(
D.zioConfig.value,
D.zioConfigMagnolia.value,
D.zioConfigTypesafe.value,
D.zioLogging.value,
D.zioLoggingSl4j.value,
D.logback.value,
D.jansi.value,
D.logstash.value,
),
libraryDependencies += D.mongo.value,
libraryDependencies ++= Seq(
D.munit.value,
D.embedMongo.value,
D.zioTest.value,
D.zioTestSbt.value,
D.zioTestMagnolia.value,
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)
.settings(
Compile / mainClass := Some("org.hyperledger.identus.mediator.MediatorStandalone"),
Docker / maintainer := "atala@iohk.io",
Docker / dockerUsername := Some("hyperledger"),
Docker / dockerRepository := Some("ghcr.io"),
Docker / packageName := "identus-mediator",
dockerExposedPorts := Seq(8080),
dockerBaseImage := "openjdk:11",
dockerUpdateLatest := true,
)
.settings(Test / parallelExecution := false)
.settings(
// WebScalaJSBundlerPlugin
scalaJSProjects := Seq(webapp),
/** scalaJSPipeline task runs scalaJSDev when isDevMode is true, runs scalaJSProd otherwise. scalaJSProd task runs
* all tasks for production, including Scala.js fullOptJS task and source maps scalaJSDev task runs all tasks for
* development, including Scala.js fastOptJS task and source maps.
*/
Assets / pipelineStages := Seq(scalaJSPipeline, gzip),
// pipelineStages ++= Seq(digest, gzip), //Compression - If you serve your Scala.js application from a web server, you should additionally gzip the resulting .js files.
Compile / unmanagedResourceDirectories += baseDirectory.value / "src" / "main" / "extra-resources",
// Compile / unmanagedResourceDirectories += (baseDirectory.value.toPath.getParent.getParent / "docs-build" / "target" / "mdoc").toFile,
// Compile / unmanagedResourceDirectories += (baseDirectory.value.toPath.getParent.getParent / "serviceworker" / "target" / "scala-3.3.3" / "fmgp-serviceworker-fastopt").toFile,
Compile / compile := ((Compile / compile) dependsOn scalaJSPipeline).value,
// Frontend dependency configuration
Assets / WebKeys.packagePrefix := "public/",
Runtime / managedClasspath += (Assets / packageBin).value,
)
.settings(run / fork := true)
.settings(envVars ++= ENV.envVars)
.enablePlugins(WebScalaJSBundlerPlugin)
.enablePlugins(JavaAppPackaging, DockerPlugin)
lazy val webapp = project
.in(file("webapp"))
.settings(publish / skip := true)
.settings(Test / test := {})
.settings(name := "webapp")
.configure(scalaJSBundlerConfigure)
.configure(buildInfoConfigure)
.settings(
libraryDependencies ++= Seq(D.laminar.value, D.waypoint.value, D.upickle.value),
libraryDependencies ++= Seq(D.zio.value, D.zioJson.value),
libraryDependencies ++= Seq(D.scalaDID.value, D.scalaDID_peer.value),
Compile / npmDependencies ++= NPM.qrcode ++ NPM.materialDesign ++ NPM.sha256,
)
.settings(
stShortModuleNames := true,
webpackBundlingMode := BundlingMode.LibraryAndApplication(), // BundlingMode.Application,
Compile / scalaJSModuleInitializers += {
org.scalajs.linker.interface.ModuleInitializer.mainMethod("org.hyperledger.identus.mediator.App", "main")
},
)
// ############################
// #### Release process #####
// ############################
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations.*
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
ReleaseStep(releaseStepTask(mediator / Docker / stage)),
setNextVersion
)