-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle.kts
224 lines (202 loc) · 7.96 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
import enforcer.rules.RequireGradleVersion
import enforcer.rules.RequireJavaVendor
import enforcer.rules.RequireJavaVersion
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import org.gradle.api.JavaVersion.VERSION_17
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
idea
`java-library`
jacoco
`maven-publish`
kotlin("jvm")
kotlin("kapt")
kotlin("plugin.spring") apply false
id("org.springframework.boot") apply false
// https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/
id("io.spring.dependency-management") apply false
id("com.google.cloud.tools.jib") apply false
id("com.palantir.git-version")
id("com.github.ben-manes.versions")
id("org.kordamp.gradle.project-enforcer")
}
java.sourceCompatibility = VERSION_17
java.targetCompatibility = VERSION_17
// Disable building any artifacts for the rootProject
tasks.withType<Jar> {
this.enabled = false
}
tasks.withType<BootJar> {
this.enabled = false
}
buildscript {
dependencies {
// https://github.com/GoogleContainerTools/jib-extensions/blob/master/first-party/jib-spring-boot-extension-gradle/README.md
classpath("com.google.cloud.tools:jib-spring-boot-extension-gradle:0.1.0")
}
}
allprojects {
val projectGroupId: String by project
group = projectGroupId
val projectVersion: String by project
version = projectVersion
apply {
plugin("java")
plugin("java-library")
}
repositories {
mavenLocal()
mavenCentral()
}
}
subprojects {
val projectGroupId: String by project
group = projectGroupId
val projectVersion: String by project
version = projectVersion
apply {
plugin("java")
plugin("java-library")
plugin("jacoco")
plugin("kotlin")
plugin("kotlin-kapt")
plugin("org.jetbrains.kotlin.plugin.spring")
plugin("org.springframework.boot")
// https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/
plugin("io.spring.dependency-management")
plugin("com.palantir.git-version")
plugin("com.github.ben-manes.versions")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = VERSION_17.majorVersion
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
// Run the compiler as a separate process.
// https://docs.gradle.org/current/userguide/performance.html#compiler_daemon
options.isFork = true
}
// https://docs.gradle.org/current/userguide/performance.html#parallel_test_execution
tasks.withType<Test>().configureEach {
// The normal approach is to use some number less than or equal to the number of CPU cores you have,
// such as this algorithm:
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
// To fork a new test VM after a certain number of tests have run
setForkEvery(100)
}
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
tasks.withType<Test> {
// Configuration parameters to execute top-level classes in parallel but methods in the same thread
// https://www.jvt.me/posts/2021/03/11/gradle-speed-parallel/
systemProperties["junit.jupiter.execution.parallel.enabled"] = "true"
systemProperties["junit.jupiter.execution.parallel.mode.default"] = "concurrent"
systemProperties["junit.jupiter.execution.parallel.mode.classes.default"] = "concurrent"
// Discover and execute JUnit Platform-based tests
useJUnitPlatform()
failFast = true
// https://technology.lastminute.com/junit5-kotlin-and-gradle-dsl/
testLogging {
// set options for log level LIFECYCLE
events = mutableSetOf(FAILED, PASSED, SKIPPED, STANDARD_OUT)
exceptionFormat = FULL
showStandardStreams = true
showExceptions = true
showCauses = true
showStackTraces = true
// set options for log level DEBUG and INFO
debug {
events = mutableSetOf(FAILED, PASSED, SKIPPED, STANDARD_OUT)
exceptionFormat = FULL
}
info {
events = debug.events
exceptionFormat = debug.exceptionFormat
}
}
// report is always generated after tests run
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
// tests are required to run before generating the report
dependsOn(tasks.test)
reports {
csv.required.set(true)
}
}
// Disable for take of building Spring Boot executable jar for most of the subprojects,
// Only bootstrap subproject needs it to be `true`.
tasks.withType<BootJar> {
this.enabled = false
}
// https://github.com/gradle/kotlin-dsl-samples/issues/1002
configure<DependencyManagementExtension> {
imports {
val springBootVersion: String by project
mavenBom("org.springframework.boot:spring-boot-dependencies:$springBootVersion")
val springCloudVersion: String by project
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion")
}
}
dependencies {
val guavaVersion: String by project
val hutoolVersion: String by project
val functionaljavaVersion: String by project
val functionaljava8Version: String by project
val mapstructVersion: String by project
val mockitoKotlinVersion: String by project
// Kotlin
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
// Tools
implementation("com.google.guava:guava:$guavaVersion")
implementation("cn.hutool:hutool-all:$hutoolVersion")
implementation("org.functionaljava:functionaljava:$functionaljavaVersion")
implementation("org.functionaljava:functionaljava-java8:$functionaljava8Version")
implementation("org.functionaljava:functionaljava-quickcheck:$functionaljavaVersion")
implementation("org.functionaljava:functionaljava-java-core:$functionaljavaVersion")
implementation("org.mapstruct:mapstruct:$mapstructVersion")
// https://github.com/bswsw/gradle-subprojects-sample/blob/develop/build.gradle.kts
kapt("org.mapstruct:mapstruct-processor:$mapstructVersion")
// kapt should be configured with the spring-boot-configuration-processor dependency.
// https://spring.io/guides/tutorials/spring-boot-kotlin/
kapt("org.springframework.boot:spring-boot-configuration-processor")
// Testing
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion")
}
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
}
enforce {
rule(RequireGradleVersion::class.java) {
this.setEnforcerLevel("ERROR")
val gradleVersion: String by project
this.setProperty("version", "[$gradleVersion]")
}
rule(RequireJavaVendor::class.java) {
this.setEnforcerLevel("ERROR")
val javaVendor: String by project
this.include(javaVendor)
}
rule(RequireJavaVersion::class.java) {
this.setEnforcerLevel("ERROR")
val temurinVersion: String by project
this.setProperty("version", "[$temurinVersion]")
}
}
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}