generated from hmcts/service-hmcts-crime-springboot-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
386 lines (343 loc) · 14.8 KB
/
build.gradle
File metadata and controls
386 lines (343 loc) · 14.8 KB
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
plugins {
id 'application'
id 'java'
id 'org.springframework.boot' version '4.0.0-M3'
id 'io.spring.dependency-management' version '1.1.7'
id 'jacoco'
id 'pmd'
id 'maven-publish'
id 'com.github.ben-manes.versions' version '0.53.0'
id 'org.cyclonedx.bom' version '3.0.1'
id 'au.com.dius.pact' version '4.6.17'
id 'com.gorylenko.gradle-git-properties' version '2.5.3'
id 'com.avast.gradle.docker-compose' version '0.17.19'
}
group = 'uk.gov.hmcts.cp'
version = System.getProperty('ARTEFACT_VERSION') ?: '0.0.999'
repositories {
mavenLocal()
mavenCentral()
maven { url = "https://repo.spring.io/milestone" }
maven { url = 'https://pkgs.dev.azure.com/hmcts/Artifacts/_packaging/hmcts-lib/maven/v1' }
}
apply {
from("gradle/docker.gradle")
from("gradle/pmd.gradle")
}
/* ------------ Java toolchain ------------ */
java {
toolchain {
def defaultVersion = (findProperty("JAVA_VERSION") ?: "21") as int
def providedVersion = System.getProperty("JAVA_VERSION") ?: System.getenv("JAVA_VERSION")
languageVersion = JavaLanguageVersion.of(providedVersion ? providedVersion as int : defaultVersion)
}
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:unchecked" << "-Werror"
}
tasks.withType(JavaExec).configureEach {
javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
}
/* ------------ Sources / Javadoc for Releases ------------ */
java {
withSourcesJar()
withJavadocJar()
}
tasks.withType(Javadoc).configureEach {
options.addBooleanOption('Xdoclint:none', true)
}
/* ------------ Source sets ------------ */
sourceSets {
integrationTest {
java.srcDir 'src/integrationTest/java'
resources.srcDir 'src/integrationTest/resources'
compileClasspath += sourceSets.main.output + configurations.integrationTestCompileClasspath
runtimeClasspath += sourceSets.main.output + configurations.integrationTestRuntimeClasspath
}
pactVerificationTest {
java {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
resources.srcDir 'src/pactVerificationTest/resources'
}
}
configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
testRuntimeClasspath { canBeResolved = true }
}
/* ------------ Versions from gradle.properties ------------ */
ext.vers = [
lombok : findProperty('version.lombok'),
apiSpec : findProperty('version.apiSpec'),
testcontainersBom : findProperty('version.testcontainersBom'),
cdk : findProperty('version.cdk'),
aiRag : findProperty('version.aiRag'),
mapstruct : findProperty('version.mapstruct'),
artemis : findProperty('version.artemis'),
httpclient5 : findProperty('version.httpclient5'),
springdoc : findProperty('version.springdoc'),
jacksonKotlin : findProperty('version.jacksonKotlin'),
logstashEncoder : findProperty('version.logstashEncoder'),
commonsText : findProperty('version.commonsText'),
jjwt : findProperty('version.jjwt'),
swaggerParser : findProperty('version.swaggerParser'),
azureBlob : findProperty('version.azureBlob'),
azureIdentity : findProperty('version.azureIdentity'),
mockwebserver : findProperty('version.mockwebserver'),
assertj : findProperty('version.assertj'),
restAssured : findProperty('version.restAssured'),
jacoco : findProperty('version.jacoco'),
commonsCollections: findProperty('version.commonsCollections'),
cpAuthFilter : findProperty('version.cpAuthFilter'),
cpAuditFilter : findProperty('version.cpAuditFilter'),
jobManager : findProperty('version.jobManager')
]
/* ---- Import Spring Boot BOM explicitly (helps with milestone builds) ---- */
def springBootVersion = '4.0.0-M3'
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
/* ------------ Dependencies ------------ */
dependencies {
// HMCTS APIs
implementation "uk.gov.hmcts.cp:api-cp-crime-caseadmin-case-document-knowledge:${vers.cdk}"
implementation "uk.gov.hmcts.cp:api-cp-ai-rag:${vers.aiRag}"
// HTTP
implementation "org.apache.httpcomponents.client5:httpclient5:${vers.httpclient5}"
// Mapping
implementation "org.mapstruct:mapstruct:${vers.mapstruct}"
annotationProcessor "org.mapstruct:mapstruct-processor:${vers.mapstruct}"
// Utils
implementation "org.apache.commons:commons-collections4:${vers.commonsCollections}"
implementation "org.apache.commons:commons-text:${vers.commonsText}"
// HMCTS filters
implementation "uk.gov.hmcts.cp:cp-auth-rules-filter:${vers.cpAuthFilter}"
implementation "uk.gov.hmcts.cp:cp-audit-filter-springboot:${vers.cpAuditFilter}"
// Spring
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-batch'
implementation 'org.springframework.batch:spring-batch-core'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework.boot:spring-boot-starter-opentelemetry'
// OpenAPI UI
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${vers.springdoc}"
// Jackson Kotlin (guarded fallback so version is never null)
def jacksonKotlinVer = vers.jacksonKotlin ?: '2.18.1'
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:${jacksonKotlinVer}"
// Data
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.postgresql:postgresql'
implementation 'org.springframework.boot:spring-boot-starter-flyway'
implementation 'org.flywaydb:flyway-core'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.flywaydb:flyway-database-postgresql'
// Logging
implementation "net.logstash.logback:logstash-logback-encoder:${vers.logstashEncoder}"
// Security / JSON / Swagger
implementation "io.jsonwebtoken:jjwt:${vers.jjwt}"
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
implementation "io.swagger.parser.v3:swagger-parser:${vers.swaggerParser}"
// Azure
implementation "com.azure:azure-storage-blob:${vers.azureBlob}"
implementation "com.azure:azure-identity:${vers.azureIdentity}"
//jobManager
implementation "uk.gov.hmcts.cp:task-manager-service:${vers.jobManager}"
// Testcontainers (BOM)
testImplementation("org.springframework.boot:spring-boot-testcontainers:4.0.2")
testImplementation 'org.testcontainers:postgresql:1.21.4'
testImplementation 'org.testcontainers:junit-jupiter:1.21.4'
// Something badly wrong here if we need testcontainers in none test build
implementation "org.testcontainers:testcontainers:2.0.3"
// Lombok
compileOnly "org.projectlombok:lombok:${vers.lombok}"
annotationProcessor "org.projectlombok:lombok:${vers.lombok}"
testCompileOnly "org.projectlombok:lombok:${vers.lombok}"
testAnnotationProcessor "org.projectlombok:lombok:${vers.lombok}"
// Testing
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-test'
testImplementation 'org.springframework.boot:spring-boot-test-autoconfigure'
testImplementation 'org.springframework.batch:spring-batch-test'
testImplementation "com.squareup.okhttp3:mockwebserver:${vers.mockwebserver}"
testImplementation "org.assertj:assertj-core:${vers.assertj}"
testImplementation "io.rest-assured:rest-assured:${vers.restAssured}"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
// Artemis for SSL ITs
integrationTestImplementation "org.apache.activemq:artemis-core-client:${vers.artemis}"
integrationTestImplementation "org.apache.activemq:artemis-commons:${vers.artemis}"
integrationTestImplementation "org.apache.activemq:artemis-jakarta-client:${vers.artemis}"
}
/* ------------ Spring Boot build & Git props ------------ */
springBoot {
buildInfo {
properties {
name = project.name
version = project.version.toString()
}
}
}
gitProperties {
keys = [
'git.branch',
'git.build.time',
'git.commit.id',
'git.commit.id.abbrev',
'git.commit.time',
'git.closest.tag.name',
'git.closest.tag.commit.count',
'git.dirty'
]
dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXX"
dateFormatTimeZone = "UTC"
}
/* ------------ SBOM ------------ */
tasks.cyclonedxDirectBom {
includeConfigs = ["runtimeClasspath"]
skipConfigs = ["compileClasspath", "testImplementation", "testCompileClasspath", "testRuntimeClasspath"]
componentVersion = providers.provider { project.version.toString() }
}
/* ------------ Reproducible archives ------------ */
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
/* ------------ JARs ------------ */
jar {
enabled = true
archiveClassifier.set('plain')
manifest {
attributes(
'Implementation-Title': project.name,
'Implementation-Version': project.version.toString()
)
}
if (file("CHANGELOG.md").exists()) {
from('CHANGELOG.md') { into 'META-INF' }
} else {
println "CHANGELOG.md not found, skipping inclusion in JAR"
}
}
bootJar {
archiveFileName = "${rootProject.name}-${project.version}.jar"
manifest { attributes('Implementation-Version': project.version.toString()) }
}
/* ------------ Application entrypoint ------------ */
application { mainClass = 'uk.gov.hmcts.cp.cdk.Application' }
/* ------------ Tests ------------ */
tasks.withType(Test).configureEach {
useJUnitPlatform()
systemProperty 'API_SPEC_VERSION', (findProperty('version.apiSpec') ?: project.version)
systemProperty 'spring.profiles.active', System.getProperty('spring.profiles.active') ?: 'test'
testLogging {
events "passed", "skipped", "failed"
exceptionFormat = 'full'
showStandardStreams = true
}
}
tasks.named('test') {
failFast = true
jvmArgs += [
"-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('mockito-core') }}",
"-Xshare:off"
]
}
/* ------------ Jacoco ------------ */
jacoco { toolVersion = (vers.jacoco ?: '0.8.12') }
tasks.named('jacocoTestReport') {
dependsOn tasks.named('test')
executionData fileTree(dir: layout.buildDirectory.dir("jacoco").get().asFile, include: ["*.exec"])
reports { xml.required.set(true); csv.required.set(false); html.required.set(true) }
}
tasks.named('composeBuild') { dependsOn tasks.named('bootJar') }
tasks.register('integration', Test) {
description = "Runs integration tests against docker-compose stack"
group = "Verification"
mustRunAfter tasks.named('test')
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
useJUnitPlatform()
dependsOn tasks.composeUp
finalizedBy tasks.composeDown
systemProperty 'app.baseUrl', 'http://localhost:8082/casedocumentknowledge-service'
jvmArgs = ['-Xshare:off']
testLogging {
events "passed", "skipped", "failed"
exceptionFormat = 'full'
showStandardStreams = true
}
}
tasks.named('processIntegrationTestResources') {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.named('build') { dependsOn tasks.named('test'), tasks.named('integration') }
tasks.named('check') { dependsOn tasks.named('integration') }
/* ------------ Publishing (GitHub releases safe) ------------ */
def githubActor = project.findProperty("github.actor") ?: System.getenv("GITHUB_ACTOR")
def githubToken = project.findProperty("github.token") ?: System.getenv("GITHUB_TOKEN")
def githubRepo = System.getenv("GITHUB_REPOSITORY") // e.g. org/repo
def azureADOArtifactRepository = 'https://pkgs.dev.azure.com/hmcts/Artifacts/_packaging/hmcts-lib/maven/v1'
def azureADOArtifactActor = System.getenv("AZURE_DEVOPS_ARTIFACT_USERNAME")
def azureADOArtifactToken = System.getenv("AZURE_DEVOPS_ARTIFACT_TOKEN")
publishing {
publications {
mavenJava(MavenPublication) {
artifact(tasks.named('bootJar'))
artifact(tasks.named('jar'))
artifact(tasks.named('sourcesJar'))
artifact(tasks.named('javadocJar'))
pom {
name = project.name
description = "Case Document Knowledge Service"
url = githubRepo ? "https://github.com/${githubRepo}" : "https://github.com/org/repo"
licenses {
license {
name = "Apache-2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0"
distribution = "repo"
}
}
scm {
url = githubRepo ? "https://github.com/${githubRepo}" : ""
connection = githubRepo ? "scm:git:https://github.com/${githubRepo}.git" : ""
developerConnection = githubRepo ? "scm:git:ssh://git@github.com/${githubRepo}.git" : ""
}
}
}
}
repositories {
if (githubRepo && githubActor && githubToken) {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${githubRepo}")
credentials { username = githubActor; password = githubToken }
}
} else {
logger.lifecycle("Skipping GitHubPackages publish repo (env not present).")
}
if (azureADOArtifactActor && azureADOArtifactToken) {
maven {
name = "AzureArtifacts"
url = uri(azureADOArtifactRepository)
credentials { username = azureADOArtifactActor; password = azureADOArtifactToken }
}
} else {
logger.lifecycle("Skipping AzureArtifacts publish repo (env not present).")
}
}
}
/* ------------ Dev helper ------------ */
tasks.register('printVersions') {
doLast {
println "Spring Boot: ${springBootVersion}"
println "App version: ${project.version}"
println "Java toolchain: ${java.toolchain.languageVersion.get()}"
println "Libraries map: ${ext.vers}"
println "jackson-module-kotlin resolved: ${jacksonKotlinVer}"
}
}