-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
470 lines (396 loc) · 15.9 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
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:3.1.2")
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:5.1.0.4882"
}
}
plugins {
id 'java'
id 'eclipse'
id 'idea'
id 'application'
id 'io.spring.dependency-management' version '1.1.3'
id 'org.springframework.boot' version '3.1.6'
id 'org.owasp.dependencycheck' version '8.3.1'
id 'se.patrikerdes.use-latest-versions' version '0.2.18'
id 'com.github.ben-manes.versions' version '0.51.0'
id 'org.sonarqube' version '5.1.0.4882'
id 'jacoco'
id "com.github.kt3k.coveralls" version "2.12.2"
id 'com.github.spacialcircumstances.gradle-cucumber-reporting' version '0.1.23'
id "info.solidsoft.pitest" version '1.9.11'
id 'uk.gov.hmcts.java' version '0.12.63'
}
dependencyUpdates.resolutionStrategy {
componentSelection { rules ->
rules.all { ComponentSelection selection ->
boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
}
if (rejected) {
selection.reject('Release candidate')
}
}
}
}
application {
mainClass = 'uk.gov.hmcts.ccd.UserProfileApplication'
}
apply from: './gradle/suppress.gradle'
dependencyCheck {
suppressionFile = 'dependency-check-suppressions.xml'
}
// tag::repositories[]
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://jitpack.io"
}
}
// end::repositories[]
group 'uk.gov.hmcts.ccd'
// tag::jar[]
sourceSets {
aat {
java {
srcDir('src/aat/java')
compileClasspath += main.output
runtimeClasspath += main.output
}
resources {
srcDir('src/aat/resources')
}
}
integrationTest {
java {
srcDir('src/integrationTest/java')
compileClasspath += main.output
runtimeClasspath += main.output
}
resources {
srcDir('src/integrationTest/resources')
}
}
}
jar {
archiveBaseName = 'user-profile'
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': project.version
}
}
bootJar {
archiveBaseName = 'user-profile'
}
configurations {
codacy
aatImplementation.extendsFrom(testImplementation)
aatRuntimeOnly.extendsFrom(testRuntimeOnly)
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom runtimeOnly
cucumberRuntime.extendsFrom(functionalRuntime)
all {
exclude group: 'ch.qos.logback'
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'com.h2database', module: 'h2'
}
}
// end::jar[]
// tag::dependencies[]
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
ext {
sl4jVersion = '2.0.7'
lombokVersion = '1.18.34'
reformLogging = '6.0.1'
springCloudVersion = '2022.0.3'
springSecurity = '6.1.9'
limits = [
'instruction': 6,
'branch' : 8,
'line' : 8,
'complexity' : 8,
'method' : 8,
'class' : 8
]
}
ext['junit-jupiter.version'] = '5.10.0'
ext['junit-vintage.version'] = '5.10.0'
ext['spring-framework.version'] = '6.0.14'
ext['jackson.version'] = '2.16.0'
ext['snakeyaml.version'] = '2.1'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
dependencies {
dependencySet(group: 'org.apache.tomcat.embed', version: '10.1.29') {
entry 'tomcat-embed-core'
entry 'tomcat-embed-el'
entry 'tomcat-embed-websocket'
}
}
}
dependencies {
implementation group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: '1.78'
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: reformLogging
implementation group: 'com.github.hmcts.java-logging', name: 'logging-appinsights', version: reformLogging
// CVE-2021-42550
implementation group: 'org.slf4j', name: 'slf4j-simple', version: sl4jVersion
implementation group: 'org.slf4j', name: 'slf4j-api', version: sl4jVersion
implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: sl4jVersion
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc') {
exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
}
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.2.0'
implementation "org.flywaydb:flyway-core:9.21.1"
implementation group: 'org.yaml', name: 'snakeyaml', version: '2.1'
implementation group: 'com.zaxxer', name: 'HikariCP', version: '5.0.1'
runtimeOnly group: 'org.postgresql', name: 'postgresql', version: '42.6.1'
implementation group: 'com.github.hmcts', name: 'auth-checker-lib', version: '2.1.5'
constraints {
implementation('com.google.guava:guava:33.1.0-jre') {
because 'previous versions of this transitive dependency have CVEs'
}
}
implementation group: 'javax.inject', name: 'javax.inject', version: '1'
implementation group: 'commons-fileupload', name: 'commons-fileupload', version: '1.5'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0'
implementation group: 'com.sun.mail', name: 'mailapi', version: '2.0.1'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.14'
implementation 'net.jcip:jcip-annotations:1.0'
// Force to use the latest org.springframework.security
implementation group: 'org.springframework.security', name: 'spring-security-core', version: springSecurity
implementation group: 'org.springframework.security', name: 'spring-security-config', version: springSecurity
implementation group: 'org.springframework.security', name: 'spring-security-web', version: springSecurity
implementation group: 'org.springframework.security', name: 'spring-security-crypto', version: springSecurity
aatImplementation 'com.github.hmcts:service-auth-provider-java-client:5.1.0'
codacy 'com.github.codacy:codacy-coverage-reporter:13.13.7'
testImplementation "org.junit.jupiter:junit-jupiter-api"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.0"
testImplementation "org.testcontainers:testcontainers:1.20.2"
testImplementation "org.testcontainers:junit-jupiter:1.20.2"
testImplementation 'org.testcontainers:postgresql'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testImplementation group: 'com.github.hmcts', name: 'ccd-test-definitions', version: '7.24.2'
testImplementation group: 'com.github.hmcts', name: 'befta-fw', version: '9.2.0'
//testImplementation group: 'com.github.hmcts', name: 'fortify-client', version: '1.4.2'
testImplementation 'com.github.hmcts:fortify-client:1.3.0:all'
testImplementation 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.9.11'
}
// end::dependencies[]
pitest {
targetClasses = ['uk.gov.hmcts.ccd.*']
targetTests = ['uk.gov.hmcts.ccd.auth.*',
'uk.gov.hmcts.ccd.domain.model.*',
'uk.gov.hmcts.ccd.domain.service.*'
]
excludedClasses = ['uk.gov.hmcts.ccd.UserProfileApplication']
enableDefaultIncrementalAnalysis = true
historyInputLocation = 'build/reports/pitest/fastermutationtesting'
historyOutputLocation = 'build/reports/pitest/fastermutationtestingoutput'
threads = 15
testSourceSets = [sourceSets.test]
mainSourceSets = [sourceSets.main]
fileExtensionsToFilter.addAll('xml','json')
outputFormats = ['XML', 'HTML','CSV']
mutationThreshold = 8
coverageThreshold = 0
features = ["+CLASSLIMIT(limit[15])"]
jvmArgs = ['-Xms1G','-Xmx3G']
timestampedReports = false
failWhenNoMutations = false
detectInlinedCode = true
}
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
exceptionFormat = 'full'
}
reports {
html.required = true
}
}
test {
environment("AZURE_APPLICATIONINSIGHTS_INSTRUMENTATIONKEY", "some-key")
generateCucumberReports.enabled = false
testLogging {
events "passed", "skipped", "failed"
}
}
task integrationTest(type: Test) {
description = "Runs integration tests"
group = "Verification"
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
failFast = true
}
jacocoTestReport {
dependsOn test, integrationTest
executionData(test, integrationTest)
reports {
// XML required by coveralls and for the below coverage checks
// and html are generated by default
xml.required = true
}
doLast {
def report = file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
logger.lifecycle("Checking coverage results: ${report}")
def parser = new XmlParser()
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
def results = parser.parse(report)
def percentage = {
def covered = it.'@covered' as Double
def missed = it.'@missed' as Double
((covered / (covered + missed)) * 100).round(2)
}
def counters = results.counter
def metrics = [:]
metrics << [
'instruction': percentage(counters.find { it.'@type'.equals('INSTRUCTION') }),
'branch' : percentage(counters.find { it.'@type'.equals('BRANCH') }),
'line' : percentage(counters.find { it.'@type'.equals('LINE') }),
'complexity' : percentage(counters.find { it.'@type'.equals('COMPLEXITY') }),
'method' : percentage(counters.find { it.'@type'.equals('METHOD') }),
'class' : percentage(counters.find { it.'@type'.equals('CLASS') })
]
def failures = []
metrics.each {
def limit = limits[it.key]
if (it.value < limit) {
failures.add("- ${it.key} coverage rate is: ${it.value}%, minimum is ${limit}%")
}
}
if (failures) {
logger.quiet("------------------ Code Coverage Failed -----------------------")
failures.each {
logger.quiet(it)
}
logger.quiet("---------------------------------------------------------------")
throw new GradleException("Code coverage failed")
} else {
logger.quiet("Passed Code Coverage Checks")
}
}
}
tasks.withType(Copy) {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
task fortifyScan(type: JavaExec) {
mainClass = "uk.gov.hmcts.fortifyclient.FortifyClientMainApp"
classpath += sourceSets.test.runtimeClasspath
jvmArgs = ['--add-opens=java.base/java.lang.reflect=ALL-UNNAMED']
}
check.dependsOn integrationTest
task highLevelDataSetup(type: JavaExec) {
dependsOn aatClasses
mainClass = "uk.gov.hmcts.ccd.userprofile.befta.HighLevelDataSetupApp"
classpath += configurations.cucumberRuntime + sourceSets.aat.runtimeClasspath
jvmArgs = ['--add-opens=java.base/java.lang.reflect=ALL-UNNAMED']
}
task smoke() {
description = 'Executes smoke tests against an the CCD User Profile API instance just deployed'
dependsOn aatClasses
new File("$buildDir/test-results/test").mkdirs()
copy{
from "src/aat/resources/DummyTest.xml"
into "$buildDir/test-results/test"
}
doLast {
generateCucumberReports.enabled = true
javaexec {
mainClass = "uk.gov.hmcts.ccd.userprofile.befta.UserProfileBeftaMain"
classpath += configurations.cucumberRuntime + sourceSets.aat.runtimeClasspath
args = ['--plugin', "json:${rootDir}/target/cucumber.json",
'--plugin', "junit:${buildDir}/test-results/smoke/cucumber.xml",
'--tags', '@Smoke',
'--glue', 'uk.gov.hmcts.befta.player', 'src/aat/resources/features']
jvmArgs = [ '--add-opens=java.base/java.lang.reflect=ALL-UNNAMED' ]
}
}
finalizedBy {
generateCucumberReports {
doLast{
delete "${rootDir}/BEFTA Report for Smoke Tests/"
new File("${rootDir}/BEFTA Report for Smoke Tests").mkdirs()
file("${rootDir}/target/cucumber/cucumber-html-reports").renameTo(file("${rootDir}/BEFTA Report for Smoke Tests"))
logger.quiet("Smoke test report moved to ---> file://${rootDir}/BEFTA%20Report%20for%20Smoke%20Tests/overview-features.html")
}
}
}
outputs.upToDateWhen { false }
}
task functional(type: JavaExec) {
description = "Executes functional tests against an the CCD User Profile API instance just deployed"
group = "Verification"
dependsOn aatClasses
generateCucumberReports.enabled = false
mainClass = "uk.gov.hmcts.ccd.userprofile.befta.UserProfileBeftaMain"
classpath += configurations.cucumberRuntime + sourceSets.aat.runtimeClasspath + sourceSets.main.output + sourceSets.test.output
args = [
'--threads', '1',
'--plugin', "json:${rootDir}/target/cucumber.json",
'--plugin', "junit:${buildDir}/test-results/functional/cucumber.xml",
'--tags', 'not @Ignore',
'--glue', 'uk.gov.hmcts.befta.player',
'--glue', 'uk.gov.hmcts.ccd.userprofile.befta',
'src/aat/resources/features'
]
// '--add-opens=...' added to suppress 'WARNING: An illegal reflective access operation has occurred' in uk.gov.hmcts.befta.util.CucumberStepAnnotationUtils
jvmArgs '--add-opens=java.base/java.lang.reflect=ALL-UNNAMED'
finalizedBy {
generateCucumberReports.enabled = true
logger.quiet('enabled cucumber reports ')
generateCucumberReports {
doLast{
delete "${rootDir}/BEFTA Report for Functional Tests/"
logger.quiet('deleted functional test folder')
new File("${rootDir}/BEFTA Report for Functional Tests").mkdirs()
logger.quiet('created functional test folder')
file("${rootDir}/target/cucumber/cucumber-html-reports").renameTo(file("${rootDir}/BEFTA Report for Functional Tests"))
logger.quiet('rename file')
logger.quiet("Functional test report moved to ---> file://${rootDir}/BEFTA%20Report%20for%20Functional%20Tests/overview-features.html")
}
}
}
outputs.upToDateWhen { false }
}
check.dependsOn jacocoTestReport
sonarqube {
properties {
property "sonar.projectName", "ccd-user-profile-api"
property "sonar.projectKey", "ccd-user-profile-api"
}
}
//Needs a token from https://app.codacy.com/app/%OrgOrOwner%/ccd-user-profile-api/settings/coverage
task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
mainClass = "com.codacy.CodacyCoverageReporter"
classpath = configurations.codacy
args = [
"report",
"-l",
"Java",
"-r",
"${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
]
}
cucumberReports {
outputDir = file("${projectDir}/target/cucumber")
reports = files("${projectDir}/target/cucumber.json")
notFailingStatuses = ["skipped", "passed"]
}