-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbuild.gradle
401 lines (350 loc) · 14 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
import groovy.json.JsonOutput
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
import org.openapitools.generator.gradle.plugin.tasks.ValidateTask
buildscript {
// dependabot will parse dependencies.gradle by detecting the `apply from` below
apply from: "dependencies.gradle"
}
plugins {
id "swatch.spring-boot-conventions"
id "org.sonarqube"
id "com.netflix.nebula.release"
id 'swatch.liquibase-conventions'
id 'jacoco-report-aggregation'
id 'jvm-test-suite'
}
configurations {
javaagent
}
liquibase {
activities {
main {
changelogFile 'liquibase/changelog.xml'
}
}
}
allprojects {
group 'com.redhat.swatch'
}
dependencies {
implementation project(":swatch-common-clock")
implementation project(':swatch-core')
implementation project(":api")
implementation project(":clients:rh-marketplace-client")
implementation project(":clients:product-client")
implementation project(":clients:prometheus-client")
implementation project(":clients:rbac-client")
implementation project(":clients:rhsm-client")
implementation project(":clients:subscription-client")
implementation project(":clients:contracts-client")
implementation project(":clients:swatch-internal-subscription-springboot-client")
implementation project(":clients:export-client")
implementation project(":clients:billable-usage-client")
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.kafka:spring-kafka"
// the following dep is necessary to avoid jackson kotlin warnings
implementation "com.fasterxml.jackson.module:jackson-module-kotlin"
// used to deserialize subscription/product messages from UMB
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml"
implementation "com.fasterxml.jackson.module:jackson-module-jakarta-xmlbind-annotations"
// used to connect to umb
implementation "org.springframework.boot:spring-boot-starter-activemq"
// used to parse events generated by console.redhat.com (Export Service)
implementation libraries["event-schemas"]
// used by the export feature to write CSV files
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-csv"
implementation "org.liquibase:liquibase-core"
implementation "org.postgresql:postgresql"
implementation libraries["guava"]
implementation libraries["mapstruct"]
annotationProcessor libraries["mapstruct-processor"]
testAnnotationProcessor libraries["mapstruct-processor"]
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.kafka:spring-kafka-test"
testImplementation 'org.testcontainers:postgresql'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation libraries["wiremock"]
testImplementation libraries["awaitility"]
testImplementation project(':swatch-core-test')
testImplementation project(':swatch-common-testcontainers')
testImplementation "org.hsqldb:hsqldb"
testImplementation "io.rest-assured:rest-assured"
javaagent libraries["splunk-otel-agent"]
subprojects.findAll { !Set.of(
project(':clients'),
project(':clients:quarkus'),
project(':swatch-common-platform-quarkus'),
project(':swatch-common-platform-spring-boot'),
).contains(it)}.each {
jacocoAggregation it
}
}
allprojects {
// Add a custom task to output dependency info in a machine parseable format. Used to generate dependency
// reports for Product Security.
// adapted from https://stackoverflow.com/a/34641632
// easiest to use via `./gradlew -q dependencyJson`
tasks.register('dependencyJson') {
doLast {
def collectDeps = { ResolvedDependency dependency ->
def collectedDeps = []
// depth first traversal
def dependencyStack = [dependency]
while (!dependencyStack.isEmpty()) {
ResolvedDependency current = dependencyStack.pop()
collectedDeps.add(current)
current.children.forEach { dependencyStack.push(it) }
}
return collectedDeps
}
Set allDeps = []
def projects = allprojects
.grep { project -> !project.name.endsWith("-test") }
.grep { project -> 'default' in project.configurations.names }
for (Project project : projects) {
// see https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
// "default" is all artifacts required at runtime
for (ResolvedDependency topLevelDependency : project.configurations.default.resolvedConfiguration.firstLevelModuleDependencies) {
def collectedDeps = collectDeps(topLevelDependency)
for (ResolvedDependency dependency : collectedDeps) {
// skip deps that appear to be from this project
if (dependency.moduleGroup != project.group || dependency.moduleVersion != project.version) {
allDeps.add([
group : dependency.moduleGroup,
name : dependency.moduleName,
version: dependency.moduleVersion,
])
}
}
}
}
println JsonOutput.toJson(allDeps.sort { "${it.group}:${it.name}:${it.version}" })
}
}
}
/* TODO - The directives below to generate the API classes are duplicates of the
* the directives we use for the api module. We need to DRY this up but that is
* going to require a little Gradle-fu that I don't currently possess.
*/
ext {
internal_spec_dir = "${projectDir}/src/main/spec"
tally_api_spec_file = "${internal_spec_dir}/internal-tally-api-spec.yaml"
tally_config_file = "${internal_spec_dir}/internal-tally-api-config.json"
sub_sync_api_spec_file = "${internal_spec_dir}/internal-subscriptions-sync-api-spec.yaml"
sub_sync_config_file = "${internal_spec_dir}/internal-subscriptions-sync-api-config.json"
swatch_producer_rhm_api_spec_file = "${internal_spec_dir}/internal-swatch-producer-red-hat-marketplace-api-spec.yaml"
swatch_producer_rhm_config_spec_file = "${internal_spec_dir}/internal-swatch-producer-red-hat-marketplace-api-config.json"
}
tasks.register("buildApiTally", GenerateTask) {
generatorName = "jaxrs-spec"
inputSpec = tally_api_spec_file
configFile = tally_config_file
outputDir = "$buildDir/generated/tally"
configOptions = [
interfaceOnly: "true",
generatePom: "false",
dateLibrary: "java8",
useJakartaEe: "true",
useTags: "true"
]
}
tasks.register("buildApiSubSync", GenerateTask) {
generatorName = "jaxrs-spec"
inputSpec = sub_sync_api_spec_file
configFile = sub_sync_config_file
outputDir = "$buildDir/generated/sub-sync"
configOptions = [
interfaceOnly: "true",
generatePom: "false",
dateLibrary: "java8",
useJakartaEe: "true",
useTags: "true"
]
}
tasks.register("buildApiProducerRHM", GenerateTask) {
generatorName = "jaxrs-spec"
inputSpec = swatch_producer_rhm_api_spec_file
configFile = swatch_producer_rhm_config_spec_file
outputDir = "$buildDir/generated/rhm"
configOptions = [
interfaceOnly: "true",
generatePom: "false",
dateLibrary: "java8",
useJakartaEe: "true",
useTags: "true"
]
}
tasks.register("openApiGenerate") {
dependsOn(provider {
tasks.findAll { task -> task.name.startsWith('buildApi') }
})
}
tasks.register("validateApiTally", ValidateTask) {
inputSpec = tally_api_spec_file
}
tasks.register("validateApiSubSync", ValidateTask) {
inputSpec = sub_sync_api_spec_file
}
tasks.register("apiValidate") {
dependsOn(provider {
tasks.findAll { task -> task.name.startsWith('validateApi') }
})
}
tasks.register("generateApiDocsTally", GenerateTask) {
generatorName = "html"
inputSpec = tally_api_spec_file
outputDir = "$buildDir/internal-tally-docs"
generateModelTests = false
generateApiTests = false
}
tasks.register("generateApiDocsSubSync", GenerateTask) {
generatorName = "html"
inputSpec = sub_sync_api_spec_file
outputDir = "$buildDir/internal-subscription-sync-docs"
generateModelTests = false
generateApiTests = false
}
tasks.register("generateOpenApiJsonTally", GenerateTask) {
generatorName = "openapi"
inputSpec = tally_api_spec_file
outputDir = "$buildDir/openapijson"
generateModelTests = false
generateApiTests = false
configOptions = [
outputFileName: "internal-tally-openapi.json",
useJakartaEe: "true",
]
}
tasks.register("generateOpenApiJsonSubSync", GenerateTask) {
generatorName = "openapi"
inputSpec = sub_sync_api_spec_file
outputDir = "$buildDir/openapijson"
generateModelTests = false
generateApiTests = false
configOptions = [
outputFileName: "internal-subscription-sync-openapi.json",
useJakartaEe: "true",
]
}
tasks.register("generateOpenApiJsonProducerRhM", GenerateTask) {
generatorName = "openapi"
inputSpec = swatch_producer_rhm_api_spec_file
outputDir = "$buildDir/openapijson"
generateModelTests = false
generateApiTests = false
configOptions = [
outputFileName: "internal-swatch-producer-red-hat-marketplace-openapi.json",
useJakartaEe: "true",
]
}
processResources {
from tasks.generateOpenApiJsonTally, tasks.generateOpenApiJsonSubSync, tasks.generateOpenApiJsonProducerRhM
from tally_api_spec_file, sub_sync_api_spec_file, swatch_producer_rhm_api_spec_file
}
sourceSets.main.java.srcDirs += [
"${buildDir}/generated/tally/src/gen/java",
"${buildDir}/generated/sub-sync/src/gen/java",
"${buildDir}/generated/metering/src/gen/java",
"${buildDir}/generated/rhm/src/gen/java"
]
tasks.register("downloadJavaAgent", Copy) {
into "$buildDir/javaagent"
from {
configurations.javaagent
}
rename { filename ->
'splunk-otel-javaagent.jar'
}
}
compileJava {
dependsOn processResources
dependsOn(provider {
tasks.findAll { task -> task.name.startsWith('buildApi') }
})
}
assemble.dependsOn(tasks.downloadJavaAgent)
project(":api") {
apply plugin: "swatch.java-conventions"
apply plugin: "swatch.spring-boot-dependencies-conventions"
apply plugin: "org.openapi.generator"
openApiGenerate {
// To keep ./gradlew openApiGenerate as a working task, we have to actually configure it. The
// generateApiv{1,2} tasks are the important ones, but it's handy to be able to run openApiGenerate on
// the command line and have it work across all the projects. The below configuration is just an
// inconsequential documentation generator but it's enough to let us set a dependsOn
generatorName.set("html")
inputSpec.set("${projectDir}/rhsm-subscriptions-api-v2-spec.yaml")
}
def public_apis = ["v1", "v2"]
for(api in public_apis) {
def spec = "${projectDir}/rhsm-subscriptions-api-" + api + "-spec.yaml"
def config = "${projectDir}/rhsm-subscriptions-api-" + api + "-config.json"
tasks.register("generateApi" + api, GenerateTask) {
generatorName = "jaxrs-spec"
inputSpec = spec
configFile = config
outputDir = "$buildDir/generated"
configOptions = [
interfaceOnly: "true",
generatePom: "false",
dateLibrary: "java8",
useJakartaEe: "true",
useTags: "true"
]
importMappings = [
"MetricId": "com.redhat.swatch.configuration.registry.MetricId",
"ProductId": "com.redhat.swatch.configuration.registry.ProductId",
]
typeMappings = [
"string+MetricId": "MetricId",
"string+ProductId": "ProductId",
]
}
tasks.register("validateApiSpec" + api, ValidateTask) {
inputSpec = spec
}
tasks.register("generateApiDocs" + api, GenerateTask) {
generatorName = "html"
inputSpec = config
outputDir = "$buildDir/docs"
generateModelTests = false
generateApiTests = false
}
tasks.register("generateOpenApiJson" + api, GenerateTask) {
generatorName = "openapi"
inputSpec = spec
outputDir = "$buildDir/openapijson"
generateModelTests = false
generateApiTests = false
configOptions = [
outputFileName: "rhsm-subscriptions-api-" + api + "-openapi.json"
]
}
processResources {
from tasks['generateOpenApiJson' + api]
from spec
}
tasks.openApiGenerate.dependsOn('generateApi' + api)
}
compileJava.dependsOn tasks.openApiGenerate
dependencies {
implementation project(":swatch-product-configuration")
implementation "jakarta.annotation:jakarta.annotation-api"
implementation libraries["jackson-annotations"]
implementation libraries["jakarta-validation-api"]
implementation libraries["jakarta-ws-rs"]
implementation libraries["swagger-annotations"]
implementation libraries["jsr305"]
implementation libraries["jackson-databind-nullable"]
}
sourceSets.main.java.srcDirs += ["${buildDir}/generated/src/gen/java"]
}
tasks.check.dependsOn tasks.testCodeCoverageReport
sonarqube {
properties {
property "sonar.coverage.jacoco.xmlReportPaths", "${rootProject.projectDir}/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml"
}
}
bootRun {
systemProperties = System.properties
}