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
290 lines (238 loc) · 9.25 KB
/
build.gradle
File metadata and controls
290 lines (238 loc) · 9.25 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
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.52.0'
id 'org.cyclonedx.bom' version '2.4.0'
id 'com.gorylenko.gradle-git-properties' version '2.5.3'
// Docker Compose lifecycle for integration tests
id 'com.avast.gradle.docker-compose' version '0.17.12'
}
group = 'uk.gov.hmcts.cp'
version = System.getProperty('ARTEFACT_VERSION') ?: '0.0.999'
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")
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")
java {
toolchain { languageVersion = JavaLanguageVersion.of(21) }
}
repositories {
mavenLocal()
mavenCentral()
maven { url = azureADOArtifactRepository }
}
ext {
lombokVersion = "1.18.42"
apiCourtScheduleVersion = "0.4.2"
}
sourceSets {
integrationTest {
java.srcDir 'src/integrationTest/java'
resources.srcDir 'src/integrationTest/resources'
compileClasspath += sourceSets.main.output + configurations.integrationTestCompileClasspath
runtimeClasspath += sourceSets.main.output + configurations.integrationTestRuntimeClasspath
}
}
configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
// resolvable if you later need to locate agents, etc.
testRuntimeClasspath { canBeResolved = true }
}
dependencies {
// --- Domain API ---
implementation "uk.gov.hmcts.cp:api-cp-crime-schedulingandlisting-courtschedule:$apiCourtScheduleVersion"
// --- Core web + validation ---
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
// --- Observability / Actuator / OTEL / Prometheus ---
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework.boot:spring-boot-starter-opentelemetry'
// --- OpenAPI (Boot 4 compatible) ---
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.0-M1'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.20.0'
// --- Data / DB ---
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.postgresql:postgresql'
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-database-postgresql'
// --- JSON logging / utils ---
implementation 'net.logstash.logback:logstash-logback-encoder:8.1'
implementation 'org.apache.logging.log4j:log4j-to-slf4j'
implementation 'org.apache.commons:commons-text:1.14.0'
// Keep only if you actually use JWT primitives yourself (not via Spring Security)
implementation 'io.jsonwebtoken:jjwt:0.13.0'
// --- Lombok ---
compileOnly "org.projectlombok:lombok:$lombokVersion"
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
// --- Tests ---
testImplementation 'org.springframework.boot:spring-boot-starter-test'
integrationTestImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'io.rest-assured:rest-assured:5.5.6'
}
springBoot {
buildInfo {
properties {
name = project.name
version = project.version.toString()
}
}
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:unchecked" << "-Werror"
}
tasks.withType(JavaExec).configureEach {
javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
}
tasks.named('processIntegrationTestResources') {
// prevent duplicate resource collisions (e.g., application-docker-it.yml)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.named('test') {
useJUnitPlatform()
// Gradle 9: do NOT use failIfNoTests (removed)
jvmArgs = ['-Xshare:off']
testLogging {
events "passed", "skipped", "failed"
exceptionFormat = 'full'
showStandardStreams = true
}
reports { junitXml.required.set(true); html.required.set(true) }
}
tasks.withType(Test).configureEach {
// remove failIfNoTests (not available on Gradle 9)
// if you want to fail when filters match nothing, you can enable:
// failOnNoMatchingTests = true
}
jacoco { toolVersion = "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) }
}
pmd {
ruleSets = []
ruleSetFiles = files(".github/pmd-ruleset.xml")
ignoreFailures = false
}
tasks.withType(Pmd).configureEach {
reports { xml.required.set(true); html.required.set(true) }
}
tasks.named("pmdMain").configure { onlyIf { gradle.startParameter.taskNames.contains(name) } }
tasks.named("pmdTest").configure { enabled = false }
tasks.named("pmdIntegrationTest").configure { enabled = false }
tasks.named("dependencyUpdates").configure {
def isNonStable = { String v ->
def stableKeyword = ['RELEASE','FINAL','GA'].any { q -> v.toUpperCase().contains(q) }
def regex = /^[0-9,.v-]+$/
!stableKeyword && !(v ==~ regex)
}
rejectVersionIf { isNonStable(candidate.version) && !isNonStable(currentVersion) }
}
cyclonedxBom {
includeConfigs = ["runtimeClasspath"]
skipConfigs = ["compileClasspath", "testImplementation"]
schemaVersion = "1.6"
componentVersion = providers.provider { project.version.toString() }
destination = layout.buildDirectory.dir("reports").get().asFile
}
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
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' }
}
}
bootJar {
archiveFileName = "${rootProject.name}-${project.version}.jar"
manifest { attributes('Implementation-Version': project.version.toString()) }
}
// Build app before compose build (your compose should COPY the bootJar)
tasks.named('composeBuild') { dependsOn tasks.named('bootJar') }
/* ---------------- Docker Compose–driven Integration Tests ---------------- */
dockerCompose {
useComposeFiles = ['docker/docker-compose.integration.yml']
startedServices = ['db', 'app']
buildBeforeUp = true
waitForTcpPorts = true
upAdditionalArgs = ['--wait', '--wait-timeout', '120']
captureContainersOutput = true
removeOrphans = true
stopContainers = true
removeContainers = true
projectName = "${rootProject.name}-it".replaceAll('[^A-Za-z0-9]', '')
useDockerComposeV2 = true
dockerExecutable = 'docker'
}
tasks.register('integration', Test) {
description = "Runs integration tests against docker-compose stack"
group = "Verification"
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
useJUnitPlatform()
dependsOn tasks.composeUp
finalizedBy tasks.composeDown
systemProperty 'app.baseUrl', 'http://localhost:8082'
jvmArgs = ['-Xshare:off']
testLogging {
events "passed", "skipped", "failed"
exceptionFormat = 'full'
showStandardStreams = true
}
}
// Ensure CI “build/check” includes integration tests
tasks.named('check') { dependsOn tasks.named('integration') }
tasks.named('build') { dependsOn tasks.named('integration') }
/* ---------------- Publishing ---------------- */
publishing {
publications {
mavenJava(MavenPublication) {
artifact(tasks.named('bootJar'))
artifact(tasks.named('jar'))
pom {
name = project.name
description = "Case Document Knowledge Service"
url = "https://github.com/${githubRepo ?: 'org/repo'}"
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${githubRepo ?: 'org/repo'}")
credentials { username = githubActor; password = githubToken }
}
maven {
name = "AzureArtifacts"
url = uri(azureADOArtifactRepository)
credentials { username = azureADOArtifactActor; password = azureADOArtifactToken }
}
}
}
application {
mainClass = 'uk.gov.hmcts.cp.Application'
}