-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.gradle.kts
716 lines (636 loc) · 19.7 KB
/
build.gradle.kts
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
/*
* Copyright (c) 2024 Elide Technologies, Inc.
*
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://opensource.org/license/mit/
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under the License.
*/
/**
* Elide Runtime
*/
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.report.ReportMergeTask
import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.dokka.versioning.VersioningConfiguration
import org.jetbrains.dokka.versioning.VersioningPlugin
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension
import org.owasp.dependencycheck.reporting.ReportGenerator.Format.HTML
import org.owasp.dependencycheck.reporting.ReportGenerator.Format.SARIF
import java.util.Properties
import kotlinx.kover.gradle.plugin.dsl.GroupingEntityType
import kotlinx.kover.gradle.plugin.dsl.MetricType
import kotlinx.validation.KotlinApiCompareTask
import elide.internal.conventions.project.Projects
plugins {
idea
java
`jvm-toolchains`
alias(libs.plugins.gradle.checksum)
alias(libs.plugins.gradle.testretry)
alias(libs.plugins.kotlinx.plugin.abiValidator)
alias(libs.plugins.nexusPublishing)
alias(libs.plugins.spdx.sbom)
id(libs.plugins.detekt.get().pluginId)
id(libs.plugins.dokka.get().pluginId)
id(libs.plugins.kover.get().pluginId)
id(libs.plugins.sonar.get().pluginId)
id(libs.plugins.spotless.get().pluginId)
alias(libs.plugins.elide.conventions)
}
group = "dev.elide"
// Set version from `.version` if stamping is enabled.
val versionFile: File = layout.projectDirectory.file(".version").asFile
version = if (hasProperty("elide.stamp") && properties["elide.stamp"] == "true") {
versionFile.readText().trim().replace("\n", "").ifBlank {
throw IllegalStateException("Failed to load `.version`")
}
} else {
"1.0-SNAPSHOT"
}
// Load property sources.
val props = Properties().apply {
if (hasProperty("elide.ci") && properties["elide.ci"] == "true") {
if (layout.projectDirectory.file("gradle-ci.properties").asFile.exists()) {
load(file("gradle-ci.properties").inputStream())
}
} else {
if (layout.projectDirectory.file("local.properties").asFile.exists()) {
load(file("local.properties").inputStream())
}
}
}
val isCI = hasProperty("elide.ci") && properties["elide.ci"] == "true"
val javaLanguageVersion = properties["versions.java.language"] as String
val kotlinLanguageVersion = properties["versions.kotlin.language"] as String
val nodeVersion: String by properties
val enableOwasp: String? by properties
val buildSamples: String by properties
val buildDocs: String by properties
val buildDeprecated: String by properties
val buildEmbedded: String by properties
val buildAuxImage: String by properties
val buildDocsModules: String by properties
buildscript {
repositories {
maven {
name = "elide-snapshots"
url = uri("https://maven.elide.dev")
content {
includeGroup("dev.elide")
includeGroup("org.capnproto")
}
}
maven {
name = "oss-snapshots"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
content {
includeGroup("dev.elide")
}
}
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath(libs.bouncycastle)
classpath(libs.bouncycastle.util)
classpath(libs.guava)
classpath(libs.h2)
classpath(libs.jgit)
classpath(libs.jgit)
classpath(libs.json)
classpath(libs.kotlinpoet)
classpath(libs.okio)
classpath(libs.owasp)
classpath(libs.plugin.kotlinx.atomicfu)
classpath(libs.protobuf.java)
classpath(libs.protobuf.util)
if (hasProperty("elide.pluginMode") && properties["elide.pluginMode"] == "repository") {
classpath("dev.elide.buildtools:plugin:${properties["elide.pluginVersion"] as String}")
}
}
if (findProperty("elide.lockDeps") == "true") {
configurations.classpath {
resolutionStrategy.activateDependencyLocking()
}
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(22)
}
}
dependencies {
// Kover: Coverage Reporting
kover(projects.packages.base)
kover(projects.packages.cli)
kover(projects.packages.core)
kover(projects.packages.graalvm)
kover(projects.packages.graalvmJava)
kover(projects.packages.graalvmJvm)
kover(projects.packages.graalvmKt)
kover(projects.packages.graalvmLlvm)
kover(projects.packages.graalvmPy)
kover(projects.packages.graalvmRb)
kover(projects.packages.http)
kover(projects.packages.proto.protoCore)
kover(projects.packages.proto.protoKotlinx)
kover(projects.packages.proto.protoProtobuf)
kover(projects.packages.server)
kover(projects.packages.ssr)
kover(projects.packages.test)
if (buildDeprecated == "true") {
kover(project(":packages:wasm"))
kover(project(":packages:serverless"))
kover(project(":packages:embedded"))
kover(project(":tools:processor"))
}
if (buildDocs == "true") {
val dokkaPlugin by configurations
dokkaPlugin(libs.plugin.dokka.versioning)
dokkaPlugin(libs.plugin.dokka.templating)
dokkaPlugin(libs.plugin.dokka.kotlinAsJava)
dokkaPlugin(libs.plugin.dokka.mermaid)
}
}
// --------------------------------------------------------------------------------------------------------------------
// EXTENSIONS
// --------------------------------------------------------------------------------------------------------------------
// --- IntelliJ IDEA --------------------------------------------------------------------------------------------------
//
idea {
project {
jdkName = (properties["elide.jvm"] as? String) ?: javaLanguageVersion
languageLevel = IdeaLanguageLevel(javaLanguageVersion)
vcs = "Git"
}
}
// --- Sonatype -------------------------------------------------------------------------------------------------------
//
nexusPublishing {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
// --- Detekt ---------------------------------------------------------------------------------------------------------
//
detekt {
parallel = true
ignoreFailures = true
config.from(files("config/detekt/detekt.yml"))
baseline = file("config/detekt/baseline.xml")
buildUponDefaultConfig = true
enableCompilerPlugin = true
basePath = projectDir.absolutePath
}
// --- Spotless -------------------------------------------------------------------------------------------------------
//
spotless {
isEnforceCheck = false
kotlinGradle {
target("*.gradle.kts")
diktat(libs.versions.diktat.get()).configFile(
layout.projectDirectory.file("config/diktat/diktat.yml"),
)
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
mapOf(
"ktlint_standard_no-wildcard-imports" to "disabled",
),
)
}
}
// --- Sonar ----------------------------------------------------------------------------------------------------------
//
sonar {
properties {
property("sonar.verbose", "true")
property("sonar.projectKey", "elide-dev_v3")
property("sonar.organization", "elide-dev")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.dynamicAnalysis", "reuseReports")
property("sonar.junit.reportsPath", "build/reports/")
property("sonar.java.coveragePlugin", "jacoco")
property("sonar.java.enablePreview", "true")
property("sonar.sourceEncoding", "UTF-8")
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/kover/report.xml")
listOf(
"sonar.java.checkstyle.reportPaths" to "build/reports/checkstyle/main.xml",
"sonar.java.pmd.reportPaths" to "build/reports/pmd/main.xml",
"sonar.sarifReportPaths" to "reports/detekt/detekt.sarif",
"sonar.kotlin.ktlint.reportPaths" to "",
"sonar.kotlin.diktat.reportPaths" to "",
).filter { it.second.isNotBlank() }.forEach {
property(it.first, it.second)
}
}
}
// --- Kover ----------------------------------------------------------------------------------------------------------
//
koverReport {
defaults {
filters {
includes {
packages("elide")
classes("elide.*")
}
excludes {
annotatedBy("*Generated*")
packages(
"tools.elide",
"elide.cli",
"elide.data",
"elide.embedded.feature",
"elide.proto",
"elide.runtime.feature",
"elide.tool",
"elide.tools",
"elide.vfs",
"google",
"kotlinx",
"webutil",
)
}
}
xml {
onCheck = false
}
html {
onCheck = false
title = "Elide Coverage"
}
binary {
onCheck = true
}
verify {
rule {
isEnabled = true
entity = GroupingEntityType.APPLICATION
bound {
minValue = 10
maxValue = 99
metric = MetricType.LINE
}
bound {
minValue = 10
maxValue = 99
metric = MetricType.BRANCH
}
bound {
minValue = 10
maxValue = 99
metric = MetricType.INSTRUCTION
}
}
}
}
}
// --- API Pinning ----------------------------------------------------------------------------------------------------
//
apiValidation {
nonPublicMarkers +=
listOf(
"elide.annotations.Internal",
)
ignoredProjects +=
listOf(
"cli",
"sqlite",
"transport",
"transport-common",
"transport-kqueue",
"transport-epoll",
"transport-uring",
"proto",
"reports",
).plus(
if (buildAuxImage == "true") {
listOf(
"auximage",
)
} else {
emptyList()
},
).plus(
if (buildDocs == "true" && buildDocsModules == "true") {
listOf(
"architecture",
"docs",
"guide",
)
} else {
emptyList()
},
).plus(
if (buildDeprecated == "true") {
listOf(
"bom",
"processor",
)
} else {
emptyList()
},
).plus(
if (buildEmbedded == "true") {
listOf(
"embedded",
)
} else {
emptyList()
},
)
}
// Conditional plugins to apply.
if (enableOwasp == "true") apply(plugin = "org.owasp.dependencycheck")
// --- Node JS --------------------------------------------------------------------------------------------------------
//
plugins.withType(NodeJsRootPlugin::class.java) {
val nodejs = the<NodeJsRootExtension>()
nodejs.apply {
download = true
}
the<NodeJsRootExtension>().version = nodeVersion
if (nodeVersion.contains("canary")) {
the<NodeJsRootExtension>().downloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
}
plugins.withType(YarnPlugin::class.java) {
val yarn = the<YarnRootExtension>()
yarn.apply {
yarnLockMismatchReport = YarnLockMismatchReport.WARNING
reportNewYarnLock = false
yarnLockAutoReplace = false
lockFileDirectory = rootDir
lockFileName = "gradle-yarn.lock"
}
}
// --- OWASP Dependency Check -----------------------------------------------------------------------------------------
//
configure<DependencyCheckExtension> {
// Top-level settings
format = listOf(HTML, SARIF).joinToString(",") { it.toString() }
scanBuildEnv = true
scanDependencies = true
autoUpdate = true
// Caching
cache.central = true
cache.ossIndex = true
cache.nodeAudit = true
// NVD Settings
nvd.apiKey = System.getenv("NVD_API_KEY")
nvd.validForHours = 12
// Analyzer settings
suppressionFile = "config/owasp/owasp-suppressions.xml"
scanConfigurations = listOf("compileClasspath", "runtimeClasspath", "classpath")
analyzers.archiveEnabled = true
analyzers.assemblyEnabled = false
analyzers.bundleAuditEnabled = false
analyzers.centralEnabled = true
analyzers.jarEnabled = true
analyzers.knownExploitedEnabled = true
analyzers.msbuildEnabled = false
analyzers.nodeEnabled = false
analyzers.opensslEnabled = true
analyzers.ossIndex.enabled = true
analyzers.experimentalEnabled = false
}
// --------------------------------------------------------------------------------------------------------------------
// TASKS
// --------------------------------------------------------------------------------------------------------------------
tasks {
// --- Tasks: Kotlin/NPM
//
withType(KotlinNpmInstallTask::class.java).configureEach {
(packageJsonFiles as MutableList<RegularFile>).addFirst(layout.projectDirectory.file("package.json"))
args.add("--ignore-engines")
outputs.upToDateWhen {
layout.projectDirectory.dir("node_modules").asFile.exists()
}
}
withType(KotlinPackageJsonTask::class.java).configureEach {
packageJson = file("package.json")
}
// --- Tasks: Detekt
//
val detektMergeSarif: TaskProvider<ReportMergeTask> by registering(ReportMergeTask::class) {
output.set(layout.buildDirectory.file("reports/detekt/detekt.sarif"))
}
val detektMergeXml: TaskProvider<ReportMergeTask> by registering(ReportMergeTask::class) {
output.set(layout.buildDirectory.file("reports/detekt/detekt.xml"))
}
withType(Detekt::class) detekt@{
finalizedBy(detektMergeSarif, detektMergeXml)
reports.sarif.required = true
reports.xml.required = true
}
// --- Task: Resolve and Lock All Configurations
//
val resolveAndLockAll by registering {
doFirst {
require(gradle.startParameter.isWriteDependencyLocks)
}
doLast {
configurations.filter {
// Add any custom filtering on the configurations to be resolved
it.isCanBeResolved &&
!it.name.lowercase().let { name ->
name.contains("sources") || name.contains("documentation")
}
}.forEach { it.resolve() }
}
}
if (buildDocs == "true") {
val docAsset: (String) -> File = {
rootProject.layout.projectDirectory.file("docs/$it").asFile
}
val creativeAsset: (String) -> File = {
rootProject.layout.projectDirectory.file("creative/$it").asFile
}
val dokkaHtmlMultiModule by getting(DokkaMultiModuleTask::class) {
moduleName = "Elide API"
moduleVersion = project.version as String
outputDirectory = layout.projectDirectory.dir("docs/apidocs").asFile
suppressInheritedMembers = true
suppressObviousFunctions = true
includes.from(
listOf(
"docs/docs.md",
"docs/includes/resources.md",
).map {
layout.projectDirectory.file(it).asFile
},
)
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
footerMessage = "© 2023—2024 Elide Technologies, Inc."
homepageLink = "https://docs.elide.dev"
templatesDir = rootProject.layout.projectDirectory.dir("docs/templates").asFile
customAssets = listOf(
creativeAsset("logo/logo-wide-1200-w-r2.png"),
creativeAsset("logo/gray-elide-symbol-lg.png"),
)
customStyleSheets = listOf(
docAsset("styles/logo-styles.css"),
docAsset("styles/theme-styles.css"),
)
}
val projectVersion = project.version as String
pluginConfiguration<VersioningPlugin, VersioningConfiguration> {
version = projectVersion
versionsOrdering = listOf("1.0.0-alpha8")
olderVersionsDir = file("docs/versions")
olderVersions = listOf(file("docs/versions/1.0.0-alpha8"))
renderVersionsNavigationOnAllPages = true
}
}
}
// --- Task: Docs
//
val docs by registering {
if (buildDocs == "true") {
dependsOn(
listOf(
dokkaHtml,
dokkaHtmlMultiModule,
),
)
}
}
// --- Task: Publish BOM
//
val publishBom by registering {
description = "Publish BOM, Version Catalog, and platform artifacts to Elide repositories and Maven Central"
group = "Publishing"
dependsOn(
":packages:bom:publishAllElidePublications",
":packages:platform:publishAllElidePublications",
)
}
// --- Task: Publish Framework
//
val publishElide by registering {
description = "Publish Elide library publications to Elide repositories and Maven Central"
group = "Publishing"
dependsOn(
Projects.publishedModules.map {
project(it).tasks.named("publishAllElidePublications")
},
)
}
// --- Task: Publish Substrate
//
val publishSubstrate by registering {
description = "Publish Elide Substrate and Kotlin compiler plugins to Elide repositories and Maven Central"
group = "Publishing"
dependsOn(
Projects.publishedSubprojects.map {
gradle.includedBuild(it.substringBefore(":")).task(
listOf(
"",
it.substringAfter(":"),
"publishAllElidePublications",
).joinToString(":"),
)
},
)
}
// --- Task: Publish All Targets
//
val publishAll by registering {
description = "Publish all publications to Elide repositories and Maven Central"
group = "Publishing"
dependsOn(publishElide, publishSubstrate, publishBom)
}
// --- Task: Copy Coverage Reports
//
val copyCoverageReports by registering(Copy::class) {
dependsOn(
koverBinaryReport,
koverXmlReport,
)
from(layout.buildDirectory.dir("reports/kover")) {
include("report.bin", "report.xml", "verify.err")
rename {
it.replace("report.", "elide.")
}
}
into(layout.projectDirectory.dir(".qodana/code-coverage"))
}
// --- Task: Quick-test
//
val quicktest: TaskProvider<Task> by registering {
description = "Run all quick tests"
group = "Verification"
dependsOn(
":packages:core:jvmTest",
":packages:base:jvmTest",
":packages:graalvm:test",
)
}
// --- Task: Pre-check
//
val precheck: TaskProvider<Task> by registering {
description = "Run all pre-check tasks"
group = "Verification"
dependsOn(quicktest)
}
// --- Task: Pre-Merge
//
val preMerge by registering {
description = "Runs all the tests/verification tasks"
group = "Verification"
dependsOn(
detekt,
)
}
// --- Task: Format
//
val format: TaskProvider<Task> by registering {
description = "Run all formatting tasks"
group = "Verification"
val spotlessApply: Task by tasks
dependsOn(spotlessApply)
}
// --- Task: Sonar
//
sonar.configure {
mustRunAfter(
detekt,
koverBinaryReport,
koverXmlReport,
koverVerify,
)
}
// --- Tasks: Kover Verification
//
koverVerify.configure {
finalizedBy(copyCoverageReports)
}
// --- Tasks: Check
//
check.configure {
dependsOn(
spotlessCheck,
koverVerify,
preMerge,
precheck,
detekt,
withType(KotlinApiCompareTask::class),
)
}
}