-
Notifications
You must be signed in to change notification settings - Fork 845
Expand file tree
/
Copy pathbuild.gradle
More file actions
349 lines (303 loc) · 13.7 KB
/
build.gradle
File metadata and controls
349 lines (303 loc) · 13.7 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
import org.apache.tools.ant.filters.ReplaceTokens
import java.nio.file.Path
import java.nio.file.Paths
buildscript {
apply(from: "dependencies.gradle")
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath(libraries.springDependencyManagementGradlePlugin)
classpath(libraries.springBootGradlePlugin)
classpath(libraries.gradleJcocoPlugin)
classpath(libraries.sonarqubePlugin)
}
}
apply(from: "dependencies.gradle")
allprojects {
apply(plugin: "io.spring.dependency-management")
apply(plugin: "org.barfuin.gradle.jacocolog")
apply(plugin: "org.sonarqube")
dependencyManagement {
imports {
mavenBom(libraries.springBootBom)
}
}
repositories {
mavenCentral()
maven {
url = uri("https://build.shibboleth.net/nexus/content/repositories/releases/")
}
maven { url = uri("https://repository.mulesoft.org/releases/") }
}
}
subprojects {
/** Log each test PASSED/SKIPPED/FAILED unless disabled (-PverboseTests=false or UAA_VERBOSE_TESTS=0/off). */
def uaaVerboseTestRaw = (findProperty('verboseTests') ?: System.getenv('UAA_VERBOSE_TESTS') ?: 'true')
.toString().trim().toLowerCase()
def uaaVerboseTestEvents = !['false', '0', 'off', 'no'].contains(uaaVerboseTestRaw)
apply(plugin: "java")
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
configurations.configureEach {
exclude(group: "org.hamcrest", module: "hamcrest-all")
exclude(group: "org.hamcrest", module: "hamcrest-core")
exclude(group: "org.hamcrest", module: "hamcrest-library")
exclude(group: "org.springframework.boot", module: "spring-boot-starter-logging")
exclude(group: "org.skyscreamer", module: "jsonassert")
exclude(group: "com.vaadin.external.google", module: "android-json")
exclude(group: "com.unboundid.components", module: "json")
// Exclude opensaml-security-api and non-FIPS bouncycastle libs, and use Shadow library for FIPS compliance
exclude(group: "org.bouncycastle", module: "bcpkix-jdk15on")
exclude(group: "org.bouncycastle", module: "bcprov-jdk15on")
exclude(group: "org.bouncycastle", module: "bcutil-jdk15on")
exclude(group: "org.bouncycastle", module: "bcprov-jdk18on")
exclude(group: "org.bouncycastle", module: "bcpkix-jdk18on")
exclude(group: "org.bouncycastle", module: "bcutil-jdk18on")
resolutionStrategy {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.opensaml' && details.requested.name.startsWith("opensaml-")) {
details.useVersion "${versions.opensaml}"
details.because 'Spring Security 5.8.x allows OpenSAML 3 or 4. OpenSAML 3 has reached its end-of-life. Spring Security 6 drops support for 3, using 4.'
}
}
}
}
dependencies {
testImplementation(libraries.springBootStarterTest) {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation(libraries.hamcrest)
testImplementation(libraries.junit5JupiterApi)
testImplementation(libraries.junit5JupiterParams)
testImplementation(libraries.junit5JupiterEngine)
testImplementation(libraries.unboundIdLdapSdk)
testRuntimeOnly(libraries.jacocoAgent)
// Ensure test runtime dependencies are included
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
compileOnly(libraries.lombok)
annotationProcessor(libraries.lombok)
}
[compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:none", "-nowarn", "-parameters"]
test {
// when failFast = true AND retry is on, there is a serious issue:
// gradle might stop the test run due to the failFast but still concludes with BUILD SUCCESSFUL (if the retry is successful)
failFast = false
useJUnitPlatform()
// Reduced from 1024m to 640m - unit tests don't need as much as integration tests
jvmArgs += ["-Xmx640m",
"-XX:+StartAttachListener",
"-XX:+HeapDumpOnOutOfMemoryError",
"-XX:HeapDumpPath=/var/log/uaa-tests.hprof"
]
// Enable test timing to identify slow tests
// This helps debug CI performance issues
reports {
junitXml.required = true
html.required = true
}
testLogging {
if (uaaVerboseTestEvents) {
events("passed", "skipped", "failed")
} else {
events("failed")
}
exceptionFormat = "full"
// Set showStandardStreams=true to see all standard output from tests (there's a ton of it!)
showStandardStreams = false
showCauses = true
showExceptions = true
showStackTraces = true
}
// Add system property to enable detailed test timing
systemProperty("junit.jupiter.execution.timeout.default", System.getProperty("junit.jupiter.execution.timeout.default", "0"))
// Log slow tests to help identify bottlenecks
afterTest { descriptor, result ->
def duration = result.endTime - result.startTime
if (duration > 10000) { // 10 seconds
logger.warn("SLOW TEST: ${descriptor.className}.${descriptor.name} took ${duration}ms")
}
}
// Log summary of test execution times
afterSuite { descriptor, result ->
if (descriptor.parent == null) {
def duration = result.endTime - result.startTime
def testLabel = result.testCount == 1 ? "unit-test" : "unit-tests"
logger.lifecycle("[${project.name}] Completed ${result.testCount} ${testLabel} in ${duration}ms (passed=${result.successfulTestCount};failed=${result.failedTestCount};skipped=${result.skippedTestCount})")
}
}
}
tasks.register('integrationTest', Test) {
dependsOn subprojects.integrationTest
useJUnitPlatform()
// This prevents integrationTests from hanging indefinitely
timeout = Duration.ofMinutes(180)
// Integration test workers need same memory as unit tests
// Actual CI configuration is controlled via integration_tests.sh script
jvmArgs += ["-Xmx640m",
"-XX:+StartAttachListener",
"-XX:+HeapDumpOnOutOfMemoryError",
"-XX:HeapDumpPath=/var/log/uaa-tests.hprof"
]
// Enable JaCoCo for integration tests
jacoco {
enabled = true
}
testLogging {
if (uaaVerboseTestEvents) {
events("passed", "skipped", "failed")
} else {
events("failed")
}
exceptionFormat = "full"
// Set showStandardStreams=true to see all standard output from tests (there's a ton of it!)
showStandardStreams = false
showCauses = true
showExceptions = true
showStackTraces = true
}
// Add system property to enable detailed test timing
systemProperty("junit.jupiter.execution.timeout.default", System.getProperty("junit.jupiter.execution.timeout.default", "0"))
// Log slow tests to help identify bottlenecks
afterTest { descriptor, result ->
def duration = result.endTime - result.startTime
if (duration > 20000) { // 20 seconds
logger.warn("SLOW TEST: ${descriptor.className}.${descriptor.name} took ${duration}ms")
}
}
// Log summary of test execution times
afterSuite { descriptor, result ->
if (descriptor.parent == null) {
def duration = result.endTime - result.startTime
def testLabel = result.testCount == 1 ? "integration-test" : "integration-tests"
logger.lifecycle("[${project.name}] Completed ${result.testCount} ${testLabel} in ${duration}ms (passed=${result.successfulTestCount};failed=${result.failedTestCount};skipped=${result.skippedTestCount})")
}
}
}
tasks.register('generateDocs') {}
tasks.register('allDeps', DependencyReportTask) {}
tasks.register('writeNewPom') {
doLast {
pom {
project {
licenses {
license {
name("The Apache Software License, Version 2.0")
url("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution("repo")
}
}
}
}.writeTo("./pom.xml")
}
}
repositories {
mavenCentral()
maven {
url = uri("https://jitpack.io")
}
maven {
url = uri("https://repo.maven.apache.org/maven2")
}
}
}
sonarqube {
properties {
property "sonar.projectKey", "cloudfoundry-identity-parent"
property "sonar.organization", "cloudfoundry-1"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.exclusions", "samples/**/*.*,**/*Test.java,**/*Tests.java,**/*IT.java,**/*SecurityConfiguration.java"
property "sonar.java.source", JavaVersion.current()
}
}
project.gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
project.allprojects.collect({ it.tasks.withType(Test) }).flatten().each {
it.systemProperty("spring.profiles.active", System.getProperty("spring.profiles.active", "hsqldb"))
it.systemProperty("testId", System.getProperty("testId", ""))
it.systemProperty("zones.paths.enabled", System.getProperty("zones.paths.enabled", "true"))
}
}
tasks.register('manifests', Copy) {
dependsOn subprojects.assemble
from("uaa/src/test/resources/sample-manifests") {
include("**/*.yml")
filter(ReplaceTokens,
tokens: [
version : version,
app : System.getProperty("app", "myuaa"),
appdomain: System.getProperty("app-domain", "bosh-lite.com"),
]
)
}
into("build/sample-manifests")
}
tasks.register('cleanBootTomcatDir') {
doLast {
String tomcatBase = file("scripts/boot/tomcat/").getAbsolutePath()
delete(Path.of(tomcatBase))
Paths.get(tomcatBase, "work").toFile().mkdirs()
Paths.get(tomcatBase, "webapps").toFile().mkdirs()
}
}
tasks.register('bootWarRun', JavaExec) {
dependsOn cleanBootTomcatDir
dependsOn subprojects.assemble
classpath = files(file("uaa/build/libs/cloudfoundry-identity-uaa-0.0.0.war"))
systemProperty("server.tomcat.basedir", file("scripts/boot/tomcat/").getAbsolutePath())
systemProperty("SECRETS_DIR", System.getProperty("SECRETS_DIR", file("scripts/boot").getAbsolutePath()))
systemProperty("spring.profiles.active", System.getProperty("spring.profiles.active", "hsqldb"))
systemProperty("metrics.perRequestMetrics", System.getProperty("metrics.perRequestMetrics", "true"))
systemProperty("smtp.host", "localhost")
systemProperty("smtp.port", 2525)
systemProperty("java.security.egd", "file:/dev/./urandom")
systemProperty("CLOUDFOUNDRY_CONFIG_PATH", file("scripts/boot").getAbsolutePath())
systemProperty("server.servlet.context-path", "/uaa")
systemProperty("statsd.enabled", "true")
systemProperty("logging.config", file("scripts/boot/log4j2.properties").getAbsolutePath())
systemProperty("zones.paths.enabled", System.getProperty("zones.paths.enabled", "true"))
}
tasks.register('killUaa', Exec) {
workingDir './'
executable = 'scripts/kill_uaa.sh'
}
/**
* Writes the resolved tomcat-embed-core version (from the Spring Boot BOM) to
* {@code build/tomcat-distribution.version} for scripts that download a matching
* Apache Tomcat binary distribution (standalone integration tests).
*/
tasks.register('writeTomcatDistributionVersion') {
group = 'build'
description = 'Writes build/tomcat-distribution.version from tomcat-embed-core on cloudfoundry-identity-uaa runtimeClasspath'
def uaaProject = project(':cloudfoundry-identity-uaa')
def outFile = layout.buildDirectory.file('tomcat-distribution.version')
outputs.file(outFile)
doLast {
def cfg = uaaProject.configurations.named('runtimeClasspath').get()
def artifact = cfg.resolvedConfiguration.resolvedArtifacts.find { it.name == 'tomcat-embed-core' }
if (artifact == null) {
throw new GradleException('Could not resolve tomcat-embed-core version from :cloudfoundry-identity-uaa runtimeClasspath')
}
outFile.get().asFile.parentFile.mkdirs()
outFile.get().asFile.text = artifact.moduleVersion.id.version
}
}
tasks.register('printTomcatDistributionVersion') {
group = 'help'
description = 'Prints the Apache Tomcat version matching Spring Boot embedded tomcat-embed-core'
dependsOn('writeTomcatDistributionVersion')
doLast {
println file("${layout.buildDirectory.get().asFile}/tomcat-distribution.version").text.trim()
}
}
tasks.register('run') {
dependsOn killUaa
dependsOn ':cloudfoundry-identity-uaa:bootRun'
description = "Kills any running UAA and starts the application. Use -Pdebug to enable debug mode (starts immediately) or -Pdebugs to enable debug mode with suspend (waits for debugger). Default port 5005, configurable with -PdebugPort=<port>"
group = "application"
}