This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
sbtgen.sc
executable file
·319 lines (275 loc) · 13 KB
/
sbtgen.sc
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
#!/bin/sh
coursier launch com.lihaoyi:ammonite_2.13.0:1.6.9 --fork -M ammonite.Main -- sbtgen.sc $*
exit
!#
import java.nio.file.{FileSystems, Files}
import $ivy.`io.7mind.izumi.sbt:sbtgen_2.13:0.0.79`, izumi.sbtgen._, izumi.sbtgen.model._, izumi.sbtgen.model.LibSetting.Exclusion
import ProjectBuilder.ProjectDeps._
val settings = GlobalSettings(
groupId = "net.playq",
sbtVersion = None,
)
@main
def entrypoint(args: String*) = Entrypoint.main(ProjectBuilder.root, settings, Seq("-o", ".") ++ args)
object Targets {
final val scala212 = ScalaVersion(getScalaVersion("212"))
final val scala213 = ScalaVersion(getScalaVersion("213"))
private def getScalaVersion(v: String): String = {
s"""scala_$v.*"(.*)"""".r
.findFirstMatchIn(
Files.readString(FileSystems.getDefault.getPath("project/Versions.scala"))
).map(_.group(1)).getOrElse(throw new RuntimeException(s"Couldn't get `scala_$v` version from project/Versions.scala"))
}
val targetScala = Seq(scala213, scala212)
// val targetScala = Seq(scala212, scala213)
private val jvmPlatform = PlatformEnv(
platform = Platform.Jvm,
language = targetScala,
settings = Seq(
"scalacOptions" ++= Seq(
SettingKey(Some(scala212), None) := Defaults.Scala212Options,
SettingKey(Some(scala213), None) := Defaults.Scala213Options,
SettingKey.Default := Const.EmptySeq,
),
"scalacOptions" ++= Seq(
SettingKey(Some(scala212), Some(true)) := Seq(
"-opt:l:inline",
"-opt-inline-from:net.playq.**",
),
SettingKey(Some(scala213), Some(true)) := Seq(
"-opt:l:inline",
"-opt-inline-from:net.playq.**",
),
SettingKey.Default := Const.EmptySeq
)
)
)
final val jvm = Seq(jvmPlatform)
}
object ProjectBuilder {
object V {
val izumi = Version.VExpr("V.izumi_version")
val cats = Version.VExpr("Izumi.Deps.fundamentals_bioJVM.org_typelevel_cats_core_version")
val cats_effect = Version.VExpr("Izumi.Deps.fundamentals_bioJVM.org_typelevel_cats_effect_version")
val zio = Version.VExpr("Izumi.Deps.fundamentals_bioJVM.dev_zio_zio_version")
val zio_interop_cats = Version.VExpr("Izumi.Deps.fundamentals_bioJVM.dev_zio_zio_interop_cats_version")
val circe = Version.VExpr("V.circe")
val circe_generic_extras = Version.VExpr("V.circe_generic_extras")
val circe_derivation = Version.VExpr("V.circe_derivation")
val aws_sdk = Version.VExpr("V.aws_java_sdk")
}
object ProjectDeps {
private val circe_exclude = LibSetting.Raw("""excludeAll (ExclusionRule(organization = "io.circe"))""")
final val scala_collection_compat = Library("org.scala-lang.modules", "scala-collection-compat", Version.VExpr("V.scala_collection_compat"), LibraryType.Auto)
final val distage_core = Library("io.7mind.izumi", "distage-core", V.izumi, LibraryType.Auto)
final val distage_framework = Library("io.7mind.izumi", "distage-framework", V.izumi, LibraryType.Auto).more(circe_exclude)
final val distage_plugins = Library("io.7mind.izumi", "distage-extension-plugins", V.izumi, LibraryType.Auto)
final val distage_config = Library("io.7mind.izumi", "distage-extension-config", V.izumi, LibraryType.Auto)
final val distage_testkit = Library("io.7mind.izumi", "distage-testkit-scalatest", V.izumi, LibraryType.Auto)
final val distage_docker = Library("io.7mind.izumi", "distage-framework-docker", V.izumi, LibraryType.Auto)
final val circe = Seq(
Library("io.circe", "circe-core", V.circe, LibraryType.Auto),
Library("io.circe", "circe-generic", V.circe, LibraryType.Auto),
Library("io.circe", "circe-generic-extras", V.circe_generic_extras, LibraryType.Auto),
Library("io.circe", "circe-parser", V.circe, LibraryType.Auto),
Library("io.circe", "circe-literal", V.circe, LibraryType.Auto),
Library("io.circe", "circe-derivation", V.circe_derivation, LibraryType.Auto),
)
final val magnolia = Library("com.propensive", "magnolia", Version.VExpr("V.magnolia_version"), LibraryType.Auto)
final val scala_reflect = Library("org.scala-lang", "scala-reflect", Version.VExpr("scalaVersion.value"), LibraryType.Invariant)
final val logstage_rendering_circe = Library("io.7mind.izumi", "logstage-rendering-circe", V.izumi, LibraryType.Auto)
final val logstage_core = Library("io.7mind.izumi", "logstage-core", V.izumi, LibraryType.Auto)
final val cats_core = Library("org.typelevel", "cats-core", V.cats, LibraryType.Auto)
final val cats_effect = Library("org.typelevel", "cats-effect", V.cats_effect, LibraryType.Auto)
final val zio_core = Library("dev.zio", "zio", V.zio, LibraryType.Auto)
final val zio_interop = Library("dev.zio", "zio-interop-cats", V.zio_interop_cats, LibraryType.Auto)
final val fs2 = Library("co.fs2", "fs2-io", Version.VExpr("V.fs2"), LibraryType.Auto)
final val scalatest = Library("org.scalatest", "scalatest", Version.VExpr("V.scalatest"), LibraryType.Auto)
final val scalatestplus_scalacheck = Library("org.scalatestplus", "scalacheck-1-15", Version.VExpr("V.scalatestplus_scalacheck"), LibraryType.Auto)
final val scalacheck_shapeless = Library("com.github.alexarchambault", "scalacheck-shapeless_1.14", Version.VExpr("V.scalacheck_shapeless"), LibraryType.Auto)
final val fundamentals_bio = Library("io.7mind.izumi", "fundamentals-bio", V.izumi, LibraryType.Auto)
final val aws_dynamo = Library("software.amazon.awssdk", "dynamodb", V.aws_sdk, LibraryType.Invariant)
.more(LibSetting.Exclusions(Seq(Exclusion("log4j", "log4j"))))
final val aws_impl_apache = Library("software.amazon.awssdk", "apache-client", V.aws_sdk, LibraryType.Invariant)
.more(LibSetting.Exclusions(Seq(Exclusion("log4j", "log4j"))))
final val projector = Library("org.typelevel", "kind-projector", Version.VExpr("V.kind_projector"), LibraryType.Invariant)
.more(LibSetting.Raw("cross CrossVersion.full"))
}
object ProjectSettings {
final val sharedImports = Seq(
Import("IzumiPublishingPlugin.Keys._"),
Import("IzumiPublishingPlugin.autoImport._"),
Import("IzumiConvenienceTasksPlugin.Keys._"),
Import("sbtrelease.ReleaseStateTransformations._"),
)
final val rootProjectSettings = Defaults.SharedOptions ++ Seq(
"fork" in SettingScope.Raw("Global") := false,
"crossScalaVersions" := "Nil".raw,
"scalaVersion" := Targets.targetScala.head.value,
"coverageOutputXML" in SettingScope.Raw("Global") := true,
"coverageOutputHTML" in SettingScope.Raw("Global") := true,
"organization" in SettingScope.Raw("Global") := "net.playq",
"sonatypeProfileName" := "net.playq",
"sonatypeSessionName" := """s"[sbt-sonatype] ${name.value} ${version.value} ${java.util.UUID.randomUUID}"""".raw,
"publishTo" in SettingScope.Build :=
"""
|(if (!isSnapshot.value) {
| sonatypePublishToBundle.value
| } else {
| Some(Opts.resolver.sonatypeSnapshots)
|})
|""".stripMargin.raw,
"credentials" in SettingScope.Build += """Credentials(file(".secrets/credentials.sonatype-nexus.properties"))""".raw,
"homepage" in SettingScope.Build := """Some(url("https://www.playq.com/"))""".raw,
"licenses" in SettingScope.Build := """Seq("Apache-License" -> url("https://opensource.org/licenses/Apache-2.0"))""".raw,
"developers" in SettingScope.Build :=
"""List(
Developer(id = "playq", name = "PlayQ", url = url("https://github.com/PlayQ"), email = "platform-team@playq.net"),
)""".raw,
"scmInfo" in SettingScope.Build := """Some(ScmInfo(url("https://github.com/PlayQ/d4s"), "scm:git:https://github.com/PlayQ/d4s.git"))""".raw,
"scalacOptions" in SettingScope.Build += s"""${"\"" * 3}-Xmacro-settings:scalatest-version=${Version.VExpr("V.scalatest")}${"\"" * 3}""".raw,
"releaseProcess" := """Seq[ReleaseStep](
| checkSnapshotDependencies,
| inquireVersions,
| runClean,
| runTest,
| setReleaseVersion,
| commitReleaseVersion,
| tagRelease,
| //publishArtifacts,
| setNextVersion,
| commitNextVersion,
| pushChanges
|)""".stripMargin.raw,
// sbt 1.3.0
"onChangedBuildSource" in SettingScope.Raw("Global") := "ReloadOnSourceChanges".raw,
)
final val sharedSettings = Seq(
"scalacOptions" in SettingScope.Compile += """s"-Xmacro-settings:metricsDir=${(Compile / classDirectory).value}"""".raw,
"scalacOptions" in SettingScope.Test += """s"-Xmacro-settings:metricsDir=${(Compile / classDirectory).value}"""".raw,
"scalacOptions" in SettingScope.Test += """s"-Xmacro-settings:metricsDir=${(Test / classDirectory).value}"""".raw,
"scalacOptions" in SettingScope.Compile += """s"-Xmacro-settings:metricsRole=${(Compile / name).value};${(Compile / moduleName).value}"""".raw,
"scalacOptions" in SettingScope.Test += """s"-Xmacro-settings:metricsRole=${(Compile / name).value};${(Compile / moduleName).value}"""".raw,
"scalacOptions" in SettingScope.Test += """s"-Xmacro-settings:metricsRole=${(Test / name).value};${(Test / moduleName).value}"""".raw,
"testOptions" in SettingScope.Test += """Tests.Argument("-oDF")""".raw,
"logBuffered" in SettingScope.Test := true,
"resolvers" += "DefaultMavenRepository".raw,
"resolvers" += "Opts.resolver.sonatypeSnapshots".raw,
)
final val crossScalaSources = Defaults.CrossScalaSources
}
object Projects {
final val aws_common = ArtifactId("aws-common")
final val metrics = ArtifactId("metrics")
final val d4s = ArtifactId("d4s")
final val d4s_test = ArtifactId("d4s-test")
final val d4s_circe = ArtifactId("d4s-circe")
}
final val d4s_agg = Aggregate(
name = ArtifactId("d4s-agg"),
artifacts = Seq(
Artifact(
name = Projects.aws_common,
libs = Seq(
distage_config,
).map(_ in Scope.Compile.all),
depends = Seq.empty,
),
Artifact(
name = Projects.metrics,
libs = Seq(
distage_framework,
).map(_ in Scope.Compile.all) ++ Seq(
scala_reflect in Scope.Provided.all,
) ++ circe.map(_ in Scope.Optional.all) ++ Seq(
scalatest,
scalatestplus_scalacheck,
scalacheck_shapeless
).map(_ in Scope.Test.all),
depends = Seq.empty,
),
Artifact(
name = Projects.d4s,
libs = Seq(
cats_effect,
zio_core,
fs2,
fundamentals_bio,
aws_dynamo,
aws_impl_apache,
magnolia,
distage_plugins,
scala_collection_compat,
).map(_ in Scope.Compile.all) ++ Seq(
scalatest in Scope.Test.all,
) ++ Seq(
scala_reflect in Scope.Provided.all,
),
depends = Seq(
Projects.aws_common,
Projects.metrics,
),
),
Artifact(
name = Projects.d4s_test,
libs = Seq(
distage_docker,
distage_testkit,
).map(_ in Scope.Compile.all) ++ Seq(
zio_interop,
scalatest,
scalatestplus_scalacheck,
scalacheck_shapeless,
).map(_ in Scope.Test.all),
depends = Seq(Projects.d4s),
),
Artifact(
name = Projects.d4s_circe,
libs = circe.map(_ in Scope.Compile.all) ++ Seq(
scalatest,
scalatestplus_scalacheck,
scalacheck_shapeless
).map(_ in Scope.Test.all),
depends = Seq(Projects.d4s),
)
),
pathPrefix = Seq("."),
groups = Set(Group("dynamo")),
defaultPlatforms = Targets.jvm,
sharedSettings = Seq(
"scalacOptions" in SettingScope.Compile += "-Xmacro-settings:metricsRole=default"
),
)
final val root = Project(
name = ArtifactId("d4s-root"),
aggregates = {
Seq(d4s_agg)
},
sharedSettings = ProjectSettings.sharedSettings ++ ProjectSettings.crossScalaSources,
sharedAggSettings = Seq(
"crossScalaVersions" := "Nil".raw,
),
rootSettings = ProjectSettings.rootProjectSettings,
imports = ProjectSettings.sharedImports,
globalLibs = Seq(
(projector in Scope.Compile.all).copy(compilerPlugin = true),
),
rootPlugins = Plugins(
enabled = Seq(
Plugin("IzumiPublishingPlugin"),
Plugin("IzumiResolverPlugin"),
Plugin("IzumiConvenienceTasksPlugin"),
Plugin("SbtgenVerificationPlugin"),
),
),
globalPlugins = Plugins(
enabled = Seq(
Plugin("IzumiPublishingPlugin"),
Plugin("IzumiResolverPlugin"),
),
),
appendPlugins = Defaults.SbtGenPlugins ++ Seq(
SbtPlugin("io.7mind.izumi", "sbt-izumi-deps", Version.VExpr("PV.izumi_deps")),
),
)
}