-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathbuild.gradle
479 lines (427 loc) · 14.7 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
471
472
473
474
475
476
477
478
479
import groovy.json.JsonSlurper
import org.ajoberstar.grgit.Grgit
buildscript {
apply from: 'dependencies.gradle'
configurations.configureEach {
resolutionStrategy {
force "com.fasterxml.jackson:jackson-bom:$jacksonVersion"
}
}
repositories {
maven { url = "$repoMirrorUrl" }
maven {
url = "$repoUrl"
allowInsecureProtocol = true
}
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.ajoberstar.grgit:grgit-gradle:5.3.0'
}
}
plugins {
id "org.ajoberstar.grgit" version "5.3.0"
id "com.github.spotbugs" version "6.1.7"
id "com.adarshr.test-logger" version "4.0.0"
id "nebula.resolution-rules" version "9.0.0"
// id 'nebula.lint' version '17.2.3'
}
def cmPrivateRepoUser = System.getenv("CM_PRIVATE_REPO_USER") ?: "$defaultCmPrivateRepoUser"
def cmPrivateRepoPassword = System.getenv("CM_PRIVATE_REPO_PASSWORD") ?: "$defaultCmPrivateRepoPassword"
def springBootApps() {
subprojects.findAll { subproject -> subproject.plugins.hasPlugin('org.springframework.boot') }
}
def env = project.hasProperty('env') ? project.getProperty('env') : 'local'
// spring dependeny management override, if you remove silent errors can happen
ext['junit-jupiter.version'] = "$junitJupiterVersion"
allprojects {
repositories {
maven { url = "$repoMirrorUrl"
content {
includeGroupByRegex "com.cloudera.cdp.*"
}
}
maven { url = "$cdpRepoUrl" }
maven {
url = "$repoUrl"
allowInsecureProtocol = true
}
}
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'nebula.resolution-rules'
group = 'com.sequenceiq'
configurations {
testRuntime {
exclude group: "org.springframework.cloud"
}
}
// override Spring Depenendencies
ext['commons-codec.version'] = commonsCodecVersion
ext['hibernate.version'] = hibernateCoreVersion
ext['hibernate-validator.version'] = hibernateValidatorVersion
ext['jackson.version'] = jacksonVersion
ext['snakeyaml.version'] = snakeYamlVersion
ext['spring-framework.version'] = springFrameworkVersion
ext['jersey.version'] = jerseyCoreVersion
ext['logback.version'] = logbackVersion
ext['mockito.version'] = mockitoVersion
ext['quartz.version'] = quartzVersion
// override AWS SDK Depenendencies
ext['netty.version'] = nettyVersion
nebulaResolutionRules {
include = ['forbidden-dependencies']
}
dependencies {
resolutionRules files('forbidden-dependencies.json')
}
configurations {
all {
resolutionStrategy {
force 'commons-collections:commons-collections:3.2.2'
force "xerces:xercesImpl:$xerces"
force "io.netty:netty-codec-http2:$nettyVersion"
force "io.netty:netty-handler-proxy:$nettyVersion"
force "commons-beanutils:commons-beanutils:$commonsBeanutilsVersion"
force "commons-codec:commons-codec:$commonsCodecVersion"
force "commons-codec:commons-codec:$commonsCodecVersion"
force "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jacksonVersion"
force "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
force "org.codehaus.jackson:jackson-jaxrs:1.9.13-atlassian-2"
force "org.codehaus.jackson:jackson-mapper-asl:1.9.13-atlassian-2"
force "org.codehaus.jackson:jackson-core-asl:1.9.13-atlassian-2"
force "org.codehaus.jackson:jackson-xc:1.9.13-atlassian-2"
force "org.testng:testng:$testNgVersion"
force "org.springframework:spring-messaging:$springFrameworkVersion"
force "org.ow2.asm:asm:9.8"
force "com.google.protobuf:protobuf-java:$protobufVersion"
force "com.google.guava:guava:$guavaVersion"
force "junit:junit:$junitVersion"
force "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jacksonVersion"
force "ch.qos.logback:logback-classic:$logbackVersion"
force "ch.qos.logback:logback-core:$logbackVersion"
force "org.slf4j:slf4j-api:$slf4jApiVersion"
force "org.quartz-scheduler:quartz:$quartzVersion"
force "io.projectreactor.netty:reactor-netty-http:$reactorNettyHttp"
}
}
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'com.github.spotbugs'
apply plugin: 'jacoco'
apply plugin: 'com.adarshr.test-logger'
//apply plugin: org.sonarqube.gradle.SonarQubePlugin
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
configurations {
deployerJars
all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12'
all*.exclude group: 'com.google.guava', module: 'guava-jdk5'
all*.exclude group: 'org.hamcrest', module: 'hamcrest-library'
all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
all*.exclude group: 'org.hamcrest', module: 'hamcrest-all'
all*.exclude group: 'com.zaxxer', module: 'HikariCP-java7'
}
dependencies {
checkstyle('com.puppycrawl.tools:checkstyle:10.17.0')
deployerJars("org.springframework.build.aws:org.springframework.build.aws.maven:3.1.0.RELEASE")
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: mockitoVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: junitJupiterVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitJupiterVersion
//adds vintage engine automatically and ensures that Junit4 testcases are run by default for all projects
testImplementation(group: "org.junit.vintage", name: "junit-vintage-engine", version: junitJupiterVersion) {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher'
}
spotbugs {
toolVersion = "4.8.3"
excludeFilter = file("$rootProject.projectDir/config/spotbugs/excludeFilter.xml")
effort = com.github.spotbugs.snom.Effort.MIN
ignoreFailures = false
showProgress = true
onlyAnalyze = [ 'com.sequenceiq.cloudbreak.*' ]
maxHeapSize = '4g'
}
jacoco {
toolVersion = "0.8.11"
reportsDirectory = file("$buildDir/reports/jacoco")
}
jacocoTestReport {
reports {
xml.required = true
csv.required = true
html.required = true
}
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(
dir: it,
exclude: [
'**/converter/mapper/**',
'**/it/**',
'**/api/**',
'**/endpoint/**',
'**/domain/**',
'**/**Config**.class',
'**/**Entry**.class',
'*.json',
'*.yaml',
'*.yml',
'*.ftl'
]
)
})
}
dependsOn processResources
dependsOn compileJava
}
test {
minHeapSize = "512m"
maxHeapSize = "1g"
jvmArgs += ['--add-opens','java.base/java.util.concurrent=ALL-UNNAMED',
'-XX:+EnableDynamicAgentLoading']
useJUnitPlatform()
testlogger {
showSummary false
showStandardStreams false
}
testLogging {
showStandardStreams false
events = ["failed", "skipped"]
}
jacoco {
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpDir = file("$buildDir/jacoco/classpathdumps")
}
failFast = true
finalizedBy jacocoTestReport
}
tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
reports {
xml.enabled = false
html.enabled = true
}
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.add("-parameters")
}
checkstyle {
toolVersion = "10.12.7"
}
checkstyleMain {
ignoreFailures = false
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
configDirectory = rootProject.file("config/checkstyle")
minHeapSize = "200m"
maxHeapSize = "4g"
}
checkstyleTest {
ignoreFailures = false
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
minHeapSize = "200m"
maxHeapSize = "4g"
}
test {
testLogging {
showStandardStreams false
events = ["failed", "skipped"]
}
failFast = true
finalizedBy jacocoTestReport
}
task allDeps(type: DependencyReportTask) {}
task status {
doLast {
println grgit.status()
}
}
repositories {
maven {
url = "$repoUrl"
allowInsecureProtocol = true
}
mavenCentral()
maven { url = "$repoMirrorUrl" }
maven { url "https://cloudbreak-maven.s3.amazonaws.com/releases" }
maven { url "https://repo.spring.io/release" }
maven { url "https://plugins.gradle.org/m2/" }
maven {
authentication {
basic(BasicAuthentication)
}
credentials(PasswordCredentials) {
username "$cmPrivateRepoUser"
password "$cmPrivateRepoPassword"
}
url "https://repository.cloudera.com/cloudera/list/cm-private/"
}
}
eclipse {
classpath {
file.whenMerged {
cp -> if (project.hasProperty('protobuf')) {
cp.entries = cp.entries.findAll { element -> !element.getPath().startsWith('src/generated')}
cp.entries.addAll(
[
new org.gradle.plugins.ide.eclipse.model.SourceFolder('src/generated/main/java', null),
new org.gradle.plugins.ide.eclipse.model.SourceFolder('src/generated/main/grpc', null)
]
)
}
}
}
}
task('buildInfo', type: BuildInfoTask, dependsOn: processResources)
project.tasks.register("cleanOut") {
group = "custom"
description = "Cleans the 'out' directory in each submodule"
doLast {
delete("out")
}
}
project.tasks.register("rebuildOutResources") {
group = "custom"
description = "Cleans and rebuilds 'out/production/resources' directory in each submodule"
doLast {
var outResourcesDir = file("out/production/resources")
delete(outResourcesDir)
var srcResourcesDir = file("src/main/resources")
if (srcResourcesDir.exists()) {
outResourcesDir.mkdirs()
copy {
from(srcResourcesDir)
into(outResourcesDir)
}
}
}
}
afterEvaluate { Project project ->
if (project.name in [
'core',
'autoscale',
'freeipa',
'redbeams',
'environment',
'datalake',
'externalized-compute',
'environment-remote',
'integration-test',
'mock-infrastructure'] && project.plugins.hasPlugin('org.springframework.boot')) {
buildInfo.configure {
destination = file("$project.buildDir")
basename = project.bootJar.archiveBaseName.get()
buildVersion = project.version
}
}
if (project.name in ['freeipa-client']) {
buildInfo.configure {
destination = file("$project.buildDir")
basename = project.jar.archiveBaseName.get()
buildVersion = project.version
version = project.version
}
}
}
compileJava {
dependsOn buildInfo
}
task execute(type: JavaExec) {
if (project.hasProperty('mainClassValue')) {
mainClass = mainClassValue
classpath = sourceSets.main.runtimeClasspath
}
}
}
class BuildInfoTask extends DefaultTask {
@Internal
File destination
@Internal
String basename
@Internal
String buildVersion
@TaskAction
def writeBuildInfo() {
if (basename != null && !basename.empty) {
println "buildVersion: " + buildVersion
println "basename: " + basename
println "build destination: " + destination
List<File> applicationDestinations = []
applicationDestinations += project.file("out/production/resources")
applicationDestinations += new File(destination.toString() + "/resources/main")
destination.mkdirs()
// if using dev environment this condition is true
if (buildVersion.contains("+") || buildVersion == "unspecified") {
def grgit = Grgit.open(currentDir: project.projectDir)
buildVersion = grgit.describe(tags: true)
println "buildVersion from git: " + buildVersion
}
String activeProfile = determineActiveProfile()
println "selected profile based on version: " + activeProfile
new File(destination, "build.info").withWriter { out ->
[
"ARTIFACT_BASENAME=" + basename,
"ARTIFACT_VERSION=" + buildVersion,
].each { out.println it }
}
applicationDestinations.each {
it.mkdirs()
new File(it, "application.properties").withWriter { out ->
[
"info.app.name=" + basename,
"info.app.version=" + buildVersion,
"spring.profiles.active=" + activeProfile
].each { out.println it }
}
}
def propertiesFile = destination.toString() + "/resources/main/application.properties"
String fileContents = new File(propertiesFile).text
println "Content of $propertiesFile:\n" + fileContents
} else {
println "no build info is needed for this module"
}
}
private String determineActiveProfile() {
String activeProfile = "dev"
if (buildVersion.contains("dev") || buildVersion.equals("unspecified")) {
activeProfile = "dev"
} else if (buildVersion.contains("rc")) {
activeProfile = "rc"
} else if (buildVersion.contains("-b")) {
activeProfile = determineProfileBasedOnGbnVersion()
} else {
activeProfile = "prod"
}
return activeProfile
}
private String determineProfileBasedOnGbnVersion() {
String activeProfile = "dev"
try {
def masterReleaseVersionResp = new URL('http://release.infra.cloudera.com/hwre-api/getreleaseversion?stack=CB&releaseline=master')
.getText('utf-8', connectTimeout: 5000, readTimeout: 5000)
def json = new JsonSlurper().parseText(masterReleaseVersionResp)
println "determine GBN version on master branch:" + json.version
String latestVersionOnMaster = json.version
if (buildVersion.startsWith(latestVersionOnMaster)) {
activeProfile = "dev"
} else {
activeProfile = "dev"
}
} catch (Exception ex) {
println "Could not query version of master branch from http://release.infra.cloudera.com, falling back to 'dev' profile!"
}
return activeProfile
}
}