-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
201 lines (175 loc) · 6.36 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
@file:Suppress(
"UnstableApiUsage",
"unused",
"DSL_SCOPE_VIOLATION",
)
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.gitlab.arturbosch.detekt.Detekt
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.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import java.util.Properties
plugins {
java
alias(libs.plugins.ksp) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.kover)
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
alias(libs.plugins.sonar)
alias(libs.plugins.versionCheck)
}
// Set version from `.version` if stamping is enabled.
version = if (project.hasProperty("elide.stamp") && project.properties["elide.stamp"] == "true") {
file(".version").readText().trim().replace("\n", "").ifBlank {
throw IllegalStateException("Failed to load `.version`")
}
} else {
"1.0-SNAPSHOT"
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
val props = Properties()
val overlay = file(
if (project.hasProperty("elide.ci") && project.properties["elide.ci"] == "true") {
"gradle-ci.properties"
} else {
"local.properties"
}
)
if (overlay.exists()) props.load(overlay.inputStream())
val isCI = project.hasProperty("elide.ci") && project.properties["elide.ci"] == "true"
sonarqube {
properties {
property("sonar.projectKey", "elide-dev_buildtools")
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.coverage.jacoco.xmlReportPaths", "$buildDir/reports/kover/merged/xml/report.xml")
property("sonar.jacoco.reportPath", "build/jacoco/test.exec")
property("sonar.sourceEncoding", "UTF-8")
}
}
koverReport {
// nothing
}
subprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
plugin("org.jlleitschuh.gradle.ktlint")
plugin("org.jetbrains.kotlinx.kover")
plugin("org.sonarqube")
}
sonarqube {
properties {
property("sonar.sources", "src/main/java")
property("sonar.tests", "src/test/java")
property(
"sonar.coverage.jacoco.xmlReportPaths",
listOf(
"$buildDir/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml",
"$buildDir/reports/jacoco/testCodeCoverageReport/jacocoTestReport.xml",
"$buildDir/reports/jacoco/test/jacocoTestReport.xml",
"$buildDir/reports/kover/xml/coverage.xml",
)
)
}
}
ktlint {
debug.set(false)
verbose.set(true)
android.set(false)
outputToConsole.set(true)
ignoreFailures.set(true)
enableExperimentalRules.set(true)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}
configurations.all {
if (!name.contains("detached")) {
resolutionStrategy.activateDependencyLocking()
}
}
detekt {
config = rootProject.files("config/detekt/detekt.yml")
}
}
rootProject.plugins.withType(NodeJsRootPlugin::class.java) {
// 16+ required for Apple Silicon support
// https://youtrack.jetbrains.com/issue/KT-49109#focus=Comments-27-5259190.0-0
rootProject.the<NodeJsRootExtension>().download = true
rootProject.the<NodeJsRootExtension>().nodeVersion = "18.11.0"
}
rootProject.plugins.withType(YarnPlugin::class.java) {
rootProject.the<YarnRootExtension>().yarnLockMismatchReport = YarnLockMismatchReport.WARNING
rootProject.the<YarnRootExtension>().reportNewYarnLock = false
rootProject.the<YarnRootExtension>().yarnLockAutoReplace = true
}
tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
html.outputLocation.set(file("build/reports/detekt.html"))
}
}
tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
candidate.version.isNonStable()
}
}
fun String.isNonStable() = "^[0-9,.v-]+(-r)?$".toRegex().matches(this).not()
tasks.register("reformatAll") {
description = "Reformat all the Kotlin Code"
dependsOn("ktlintFormat")
dependsOn(gradle.includedBuild("plugin-build").task(":plugin:ktlintFormat"))
}
tasks.register("preMerge") {
description = "Runs all the tests/verification tasks on both top level and included build."
dependsOn("build", "test", "check")
dependsOn("koverVerify", "koverXmlReport")
if ((properties["buildExamples"] as? String) == "true") {
dependsOn(":example:fullstack:node:check")
dependsOn(":example:fullstack:server:check")
}
dependsOn(gradle.includedBuild("plugin-build").task(":plugin:check"))
dependsOn(gradle.includedBuild("plugin-build").task(":plugin:validatePlugins"))
dependsOn(gradle.includedBuild("plugin-build").task(":plugin:koverXmlReport"))
dependsOn(gradle.includedBuild("plugin-build").task(":plugin:koverVerify"))
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
tasks.register("resolveAndLockAll") {
doFirst {
require(gradle.startParameter.isWriteDependencyLocks)
}
dependsOn("resolveAllDependencies")
}
if (tasks.findByName("resolveAllDependencies") == null) {
tasks.register("resolveAllDependencies") {
val npmInstall = tasks.findByName("kotlinNpmInstall")
if (npmInstall != null) {
dependsOn(npmInstall)
}
doLast {
allprojects {
configurations.forEach { c ->
if (c.isCanBeResolved) {
println("Downloading dependencies for '$path' - ${c.name}")
val result = c.incoming.artifactView { lenient(true) }.artifacts
result.failures.forEach {
println("- Ignoring Error: ${it.message}")
}
}
}
}
}
}
}