-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
259 lines (219 loc) · 7.97 KB
/
build.gradle
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
plugins {
id 'io.spring.dependency-management' version '1.1.0'
id 'org.springframework.boot' version '3.0.5'
id 'com.gorylenko.gradle-git-properties' version '2.4.1'
id 'name.remal.sonarlint' version '3.0.10'
id 'nebula.lint' version '18.0.3'
id 'nu.studer.credentials' version '3.0'
id 'com.github.node-gradle.node' version '3.5.1'
id 'io.freefair.lombok' version '8.0.1'
id 'java'
id 'jacoco'
id 'eclipse'
}
ext {
nodeVersion = '19.9.0'
}
group = 'com.integralblue.demo'
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
compileJava {
options.release = 17
}
dependencies {
implementation(platform("org.testcontainers:testcontainers-bom:1.18.0"))
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.springframework:spring-context-indexer'
annotationProcessor "org.hibernate.validator:hibernate-validator-annotation-processor"
developmentOnly "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.3.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'
if (! project.hasProperty('no-testcontainers')) {
// testcontainers shouldn't be used in an actual, production environment (such as as on running in k8s, aws, etc)
// this property allows for the exclusion of testcontainers so "real" services can be used instead
runtimeOnly 'org.testcontainers:postgresql'
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
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
}
// reproducible builds
// See: https://candrews.integralblue.com/2020/06/reproducible-builds-in-java/
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
// See: https://candrews.integralblue.com/2022/10/improving-the-reproducibility-of-spring-boots-docker-image-builder/
tasks.named("bootBuildImage") {
// See: https://paketo.io/docs/howto/java/
// run the JLink tool and install a minimal JRE for runtime, reducing both image size and attack surface
environment["BPJVM_JLINK_ENABLED"] = "true"
docker {
// 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.117@sha256:1aad16b75edb2ef549ffb1fd22716b21cc2daab7f3806e80c522da1afd9e8d43"
runImage = "docker.io/paketobuildpacks/run-jammy-tiny:0.1.51@sha256:dbfaf4949a9c060314793033712c209ff4907ee96abdd221afaf1fd599b8e8f1"
buildpacks = [
"gcr.io/paketo-buildpacks/ca-certificates:3.6.1@sha256:b41cc786c7b844e91360733fcbd0863771c4498a2143da2e500dd08371e25b39",
"gcr.io/paketo-buildpacks/bellsoft-liberica:10.0.0@sha256:c09628abab643f663157deeaddfd8a6befbc7ad96f072f86fa10fd591fb1ee07",
"gcr.io/paketo-buildpacks/syft:1.26.0@sha256:644ef6c519228f8b1d65c47a1bdb07344cbe6019a8306194f80cef4735a10abf",
"gcr.io/paketo-buildpacks/executable-jar:6.6.3@sha256:128d412328d1e644aca859325afc1397bd4a53f195d95a11f7d8f36244c5af9e",
"gcr.io/paketo-buildpacks/dist-zip:5.5.2@sha256:0ed048ec74f6acb837775036919eef818cffdf4071e86cfdd5d735a4b1aff0c1",
"gcr.io/paketo-buildpacks/spring-boot:5.23.0@sha256:fc4d0db457abcb26d13adc74717e3c41ba4186ca4ef3d8d1955c04b1be683cd5",
]
}
}
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
check {
dependsOn jacocoTestCoverageVerification
}
springBoot {
buildInfo {
properties {
// necessary for reproducible builds, see https://github.com/spring-projects/spring-boot/issues/14494
time = null
}
}
}
bootJar {
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}" // don't include the version in the artifact jar name
}
jacocoTestReport {
reports {
html.required = true
xml.required = true
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.10
}
}
}
}
String generatedFrontendResources = "$buildDir/generated-resources"
String frontend = "$projectDir/frontend"
String testsExecutedMarkerName = "${projectDir}/.tests.executed"
node {
download = true
version = nodeVersion
nodeModulesDir = file("${frontend}")
npmInstallCommand = System.getenv("CI") ? 'ci' : 'install'
}
task nodeDir {
dependsOn nodeSetup
println nodeSetup.nodeDir.get()
}
npm_run_build {
dependsOn npmInstall
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"
}
npm_run_test {
dependsOn npm_run_build
setEnvironment CI:"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 {
new File(testsExecutedMarkerName).text = 'delete this file to force re-execution JavaScript tests'
}
outputs.file testsExecutedMarkerName
}
task npmCypressVersion(type: NpxTask) {
dependsOn npmInstall
command = "cypress"
args = ["--version"]
}
task npmLighthouseVersion(type: NpxTask) {
dependsOn npmInstall
command = "lhci"
args = ["--version"]
}
task generateFrontendResources(type: Copy) {
dependsOn npm_run_build
from "${frontend}/build"
into "$generatedFrontendResources/static"
outputs.dir "$generatedFrontendResources"
}
check {
dependsOn npm_run_test
}
task start {
dependsOn npm_run_build
dependsOn 'npm_start'
}
sourceSets {
main {
output.dir(generatedFrontendResources, builtBy: generateFrontendResources)
}
}
clean {
delete testsExecutedMarkerName
delete "${frontend}/build"
delete generatedFrontendResources
}
eclipse {
autoBuildTasks generateFrontendResources
}
task coverageReport() {
dependsOn jacocoTestReport
def reportFile = project.file("build/reports/jacoco/test/jacocoTestReport.xml")
inputs.file(reportFile)
doLast {
def slurper = new XmlSlurper()
slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
slurper.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
def xml = slurper.parse(reportFile)
def counter = xml.counter.find {
node -> node.@type == 'BRANCH'
}
double missed = [email protected]() ?: 0
double covered = [email protected]() ?: 0
double total = missed + covered ?: 0
double percentage = (total == 0 ? 100 : (covered / total * 100))
printf "Missed %.0f branches%n", missed
printf "Covered %.0f branches%n", covered
printf "Total %.0f%%%n", percentage
}
}
jacocoTestReport.finalizedBy coverageReport