-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle.kts
269 lines (225 loc) · 8.79 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
import com.github.gradle.node.npm.task.NpmTask
import com.github.gradle.node.npm.task.NpxTask
plugins {
id("io.spring.dependency-management") version "1.1.5"
id("org.springframework.boot") version "3.3.0"
id("com.gorylenko.gradle-git-properties") version "2.4.2"
id("name.remal.sonarlint") version "4.1.1"
//id("nebula.lint") version "18.1.0" // this plugin doesn't (currently?) support Gradle kotlin: https://github.com/nebula-plugins/gradle-lint-plugin/issues/166
id("nu.studer.credentials") version "3.0"
id("com.github.node-gradle.node") version "7.0.2"
id("io.freefair.lombok") version "8.6"
id("java")
id("jacoco")
id("eclipse")
}
val nodeVersion = "21.7.3"
// Remove when using Spring Boot 3.2 or later, as Spring Boot 3.2 will use snakeyaml 2.0: https://github.com/spring-projects/spring-boot/issues/35982
// snakeyaml 2.0 addresses CVE-2022-1471
ext["snakeyaml.version"] = "2.0"
group = "com.integralblue.demo"
version = "0.0.1-SNAPSHOT"
repositories {
mavenCentral()
}
tasks.compileJava {
options.release = 21
}
// Enable dependency locking: https://docs.gradle.org/current/userguide/dependency_locking.html
// To achieve reproducible builds, it is necessary to lock versions of dependencies and transitive dependencies such that a build with the same inputs will always resolve the same module versions.
// This is called dependency locking.
// From a security perspective, dependency locking mitigate some supply chain attack risks, as well as provide other benefits.
// From a development/maintainability perspective, dependency locking ensure that dependency changes can only occurs with commits to source control, so all dependency changes are intentional, tracked via the commit history, and enjoy all other change management benefits.
dependencyLocking {
lockAllConfigurations()
lockMode = LockMode.STRICT
}
lombok {
version = "1.18.32"
}
jacoco {
toolVersion = "0.8.12"
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.session:spring-session-jdbc")
implementation("org.liquibase:liquibase-core")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
annotationProcessor("org.hibernate.validator:hibernate-validator-annotation-processor")
testAndDevelopmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.mockito:mockito-junit-jupiter")
runtimeOnly("org.postgresql:postgresql")
runtimeOnly("net.lbruun.springboot:preliquibase-spring-boot-starter:1.5.0") // necessary to create the db schema before liquibase runs so liquibase can use the created schema
testImplementation("org.testcontainers:testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:postgresql")
}
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
/*
This plugin doesn't (currently?) support Gradle kotlin: https://github.com/nebula-plugins/gradle-lint-plugin/issues/166
gradleLint {
// "unused-exclude-by-dep" doesn"t work with BOM dependency management: https://github.com/nebula-plugins/gradle-lint-plugin/issues/224
rules = ["archaic-wrapper"]
criticalRules = [
"dependency-parentheses",
"overridden-dependency-version"] // <-- this will fail the build in the event of a violation
}
*/
sonarLint {
nodeJs {
nodeJsExecutable = project.provider{ file("${node.resolvedNodeDir.get()}/bin/node") }
}
}
// reproducible builds
// See: https://candrews.integralblue.com/2020/06/reproducible-builds-in-java/
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
// See: https://candrews.integralblue.com/2022/10/improving-the-reproducibility-of-spring-boots-docker-image-builder/
tasks.bootBuildImage {
// See: https://paketo.io/docs/howto/java/
environment = mapOf("BP_JVM_VERSION" to "21")
docker {
publishRegistry {
username = System.getenv("DOCKER_USERNAME")
password = System.getenv("DOCKER_PASSWORD")
}
// version and digest pin all image references. This ensures reproducibility.
// make sure to configure Renovate to keep these image references up to date.
// if these image references are not kept up to date, any security issues discovered within them will never be fixed.
// Use a tiny builder and run image (which produce a distroless-like image) to reduce both image size and attack surface.
builder = "docker.io/paketobuildpacks/builder-jammy-tiny:0.0.260@sha256:bd4d72adba5d73935060bd9065cd3f4d7f3814d82e8461cc259fb2fd617151f1"
runImage = "docker.io/paketobuildpacks/run-jammy-tiny:0.2.41@sha256:4e3822b34116cbd0ffdac7d99f219be39cc48faf4257c102ed6312f0d47195ff"
buildpacks = listOf(
"gcr.io/paketo-buildpacks/ca-certificates:3.8.0@sha256:24f8da8f799db87ed5266cb83adae96eed14213886098af153a30220faaecb5a",
"gcr.io/paketo-buildpacks/bellsoft-liberica:10.8.0@sha256:9c58e08737750e7d465792075bcdd5757be1f6a298d8955f3513c41a10353bbb",
"gcr.io/paketo-buildpacks/syft:1.47.0@sha256:52ccd6c25bcf368f11f452095edabe4b584d8f4675c0a13952e474a1e862b013",
"gcr.io/paketo-buildpacks/executable-jar:6.10.0@sha256:23d4959f02a071591af89dd3485fa4f89885d7bb92b2d2cc2efc5fa8ce9c2a68",
"gcr.io/paketo-buildpacks/dist-zip:5.8.0@sha256:0a57dd17bbf3fb30e1ec6505dfb6ec68cc528aed519a5d97d439de04eae1379c",
"gcr.io/paketo-buildpacks/spring-boot:5.30.0@sha256:7b277ce79b006408d9668debf9ced0a5d6c30dc3282fc1480fdfc82c87ad9371",
)
}
}
tasks.withType<Test> {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}
tasks.check {
dependsOn(tasks.jacocoTestCoverageVerification)
}
springBoot {
buildInfo {
properties {
// necessary for reproducible builds, see https://github.com/spring-projects/spring-boot/issues/14494
excludes = setOf("time")
}
}
}
tasks.bootJar {
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}" // don"t include the version in the artifact jar name
}
tasks.jacocoTestReport {
reports {
html.required = true
xml.required = true
}
}
tasks.jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = "0.10".toBigDecimal()
}
}
}
}
val generatedFrontendResources = "$buildDir/generated-resources"
val frontend = "$projectDir/frontend"
val testsExecutedMarkerName = "${projectDir}/.tests.executed"
node {
download = true
version = nodeVersion
nodeProjectDir = file("${frontend}")
npmInstallCommand = if ("true".equals(System.getenv("CI"), true)) "ci" else "install"
}
tasks.register("nodeDir") {
dependsOn(tasks.nodeSetup)
println(node.resolvedNodeDir)
}
val npm_run_build by tasks.registering(NpmTask::class) {
dependsOn(tasks.npmInstall)
npmCommand = listOf("run", "build")
inputs.files(fileTree("${frontend}/public"))
inputs.files(fileTree("${frontend}/src"))
inputs.file("${frontend}/package.json")
inputs.file("${frontend}/package-lock.json")
outputs.dir("${frontend}/build")
}
val npm_run_test by tasks.registering(NpmTask::class) {
dependsOn(npm_run_build)
npmCommand = listOf("run", "test")
environment = mapOf("CI" to "true")
inputs.files(fileTree("${frontend}/public"))
inputs.files(fileTree("${frontend}/src"))
inputs.file("${frontend}/package.json")
inputs.file("${frontend}/package-lock.json")
// allows easy triggering re-tests
doLast {
File(testsExecutedMarkerName).writeText("delete this file to force re-execution JavaScript tests")
}
outputs.file(testsExecutedMarkerName)
}
tasks.register<NpxTask>("npmCypressVersion") {
dependsOn(tasks.npmInstall)
command = "cypress"
args = listOf("--version")
}
tasks.register<NpxTask>("npmLighthouseVersion") {
dependsOn(tasks.npmInstall)
command = "lhci"
args = listOf("--version")
}
val npm_start by tasks.registering(NpmTask::class) {
dependsOn(tasks.npmInstall)
npmCommand = listOf("run", "start")
}
val generateFrontendResources by tasks.registering(Copy::class) {
dependsOn(npm_run_build)
from("${frontend}/build")
into("$generatedFrontendResources/static")
outputs.dir("$generatedFrontendResources")
}
tasks.check {
dependsOn(npm_run_test)
}
tasks.register("start") {
dependsOn(npm_run_build)
dependsOn(npm_start)
}
sourceSets {
main {
output.dir(mapOf("builtBy" to generateFrontendResources), generatedFrontendResources)
}
}
tasks.clean {
delete(testsExecutedMarkerName)
delete("${frontend}/build")
delete(generatedFrontendResources)
}
eclipse {
autoBuildTasks(generateFrontendResources)
}