-
Notifications
You must be signed in to change notification settings - Fork 27
/
build.gradle
495 lines (435 loc) · 17.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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
import static org.gradle.api.JavaVersion.VERSION_17
import static org.gradle.jvm.toolchain.JavaLanguageVersion.of
import static org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
import static org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_8
import org.jetbrains.dokka.gradle.DokkaTask
buildscript {
configurations.classpath {
resolutionStrategy {
// FORCE Gradle to use latest dynamic-version plugins.
cacheDynamicVersionsFor 0, 'seconds'
}
}
}
plugins {
alias libs.plugins.kotlin.jvm apply false
alias libs.plugins.kotlin.allopen apply false
alias libs.plugins.kotlin.jpa apply false
alias libs.plugins.detekt apply false
id 'biz.aQute.bnd.builder' apply false
alias libs.plugins.test.logger apply false
alias libs.plugins.snyk
id 'idea'
id 'application'
id 'net.corda.cordapp.cordapp-configuration'
id 'corda.root-publish'
id 'jacoco'
alias libs.plugins.dependency.check.versions // discover possible dependency version upgrades
alias libs.plugins.dokka apply false
alias libs.plugins.cyclonedx.bom apply false
alias libs.plugins.sonar
}
tasks.named("wrapper") {
gradleVersion = '8.4'
distributionType = Wrapper.DistributionType.BIN
}
def javaVersion = VERSION_17
def javaVersionNumber = javaVersion.majorVersion.toInteger()
snyk {
api = project.findProperty("snykApiToken") ?: System.getenv('SNYK_TOKEN')
arguments = project.findProperty("snykArguments") ?: '--all-sub-projects'
severity = project.findProperty("snykSeverity") ?: 'low'
autoDownload = true
autoUpdate = true
}
sonar {
properties {
property "sonar.projectKey", "corda"
property "sonar.organization", "corda"
property "sonar.host.url", "https://sonarcloud.io"
}
}
allprojects {
pluginManager.withPlugin('java') {
java {
toolchain {
languageVersion = of(javaVersionNumber)
}
withSourcesJar()
}
tasks.withType(JavaCompile).configureEach {
options.release = javaVersionNumber
options.encoding = 'UTF-8'
options.compilerArgs += [ '-XDenableSunApiLintControl', '-parameters' ]
}
tasks.withType(Test).configureEach {
useJUnitPlatform(){
if (project.hasProperty('runMultiClusterTests')) {
includeTags 'MultiCluster'
} else if (project.hasProperty('runUnstableTests')) {
includeTags 'Unstable'
} else {
excludeTags 'MultiCluster', 'Unstable'
}
}
doFirst {
systemProperty 'java.io.tmpdir', buildDir.absolutePath
jvmArgs '--add-opens', 'java.base/java.lang=ALL-UNNAMED'
}
}
}
apply plugin: 'org.jetbrains.kotlin.jvm'
if (it.toString().contains(":applications:workers:release:")) {
apply plugin: 'org.cyclonedx.bom'
cyclonedxBom.dependsOn("assemble")
cyclonedxBom {
includeConfigs = ["runtimeClasspath"]
skipProjects = [rootProject.name]
destination = file("${buildDir}/reports/SBOM")
outputName = "${project.name}-corda-runtime-os-sbom"
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions {
allWarningsAsErrors = true
languageVersion = KOTLIN_1_8
apiVersion = KOTLIN_1_8
jvmTarget = JVM_17
javaParameters = true // Useful for reflection.
freeCompilerArgs.addAll([
"-Xjvm-default=all"
])
}
}
configurations {
[ compileClasspath, testCompileClasspath, runtimeClasspath, testRuntimeClasspath ].forEach { cfg ->
configureKotlinForOSGi(cfg)
}
}
pluginManager.withPlugin('biz.aQute.bnd.builder') {
tasks.withType(aQute.bnd.gradle.TestOSGi).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = of(javaVersionNumber)
}
}
}
if (project.hasProperty('generateJavaDocWithBuild')) {
pluginManager.withPlugin('corda.javadoc-generation') {
artifacts {
archives javadocJar
}
tasks.withType(DokkaTask.class).configureEach {
moduleVersion.set(System.getenv("RELEASE_VERSION") ?: "$cordaProductVersion.$cordaRuntimeRevision")
}
}
}
tasks.register('compileAll') { task ->
description = "Compiles all the Kotlin and Java classes, including all of the test classes."
group = "verification"
task.dependsOn tasks.withType(AbstractCompile),
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile)
}
repositories {
// TODO: you really need to use the cache, otherwise no complaining when upstream repos throttle us!
// It would make sense to follow the template!
// Listed the mavenLocal repository first in case people are doing a local publication of an upstream
// module (e.g in corda-api repo).
// This would ensure that the local copy is picked up if it is available.
mavenLocal()
maven {
url = "${publicArtifactURL}/corda-dependencies-dev"
content {
// For Quasar SNAPSHOT.
includeGroup 'co.paralleluniverse'
}
}
//needed for C5 binaries
maven {
url = "$artifactoryContextUrl/corda-os-maven"
authentication {
basic(BasicAuthentication)
}
credentials {
username = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME')
password = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD')
}
}
maven {
url = "$artifactoryContextUrl/engineering-tools-maven"
authentication {
basic(BasicAuthentication)
}
credentials {
username = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME')
password = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD')
}
content {
// YourKit Java Profiler agent artifact.
// To publish agent locally:
// $ cd profiler
// $ ../gradlew publishToMavenLocal
includeGroup 'com.yourkit.corda'
}
}
def cordaUseCache = System.getenv("CORDA_USE_CACHE")
if (cordaUseCache != null) {
maven {
url = "$artifactoryContextUrl/$cordaUseCache"
name = "R3 Maven remote repositories"
authentication {
basic(BasicAuthentication)
}
credentials {
username = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME')
password = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD')
}
}
} else {
mavenCentral()
}
}
sourceSets {
integrationTest {
java {
srcDirs += [ 'src/integrationTest/java' ]
}
kotlin {
srcDirs += [ 'src/integrationTest/kotlin' ]
}
resources {
srcDirs = [ 'src/integrationTest/resources' ]
}
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
kotlin {
target {
java
compilations.integrationTest {
associateWith compilations.main
associateWith compilations.test
configurations {
integrationTestApi.extendsFrom testApi
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
[ integrationTestCompileClasspath, integrationTestRuntimeClasspath ].forEach { cfg ->
configureKotlinForOSGi(cfg)
}
}
}
}
}
tasks.register('integrationTest', Test) {
// Conversion of legacy arguments to keep old Jenkins pipeline happy
if (!postgresPort.isBlank()){
databasePort = postgresPort
databaseType = 'POSTGRES'
databaseName = postgresDb
databaseHost = postgresHost
databaseAdminUser = postgresUser
databaseAdminPassword = postgresPassword
}
inputs.property('databaseHost', databaseHost)
inputs.property('databaseName', databaseName)
inputs.property('databasePort', databasePort)
inputs.property('databaseAdminUser', databaseAdminUser)
inputs.property('databaseAdminPassword', databaseAdminPassword)
inputs.property('databaseType', databaseType)
description = "Runs integration tests."
group = "verification"
testClassesDirs = project.sourceSets["integrationTest"].output.classesDirs
classpath = project.sourceSets["integrationTest"].runtimeClasspath
systemProperty 'databaseHost', databaseHost
systemProperty 'databaseName', databaseName
systemProperty 'databasePort', databasePort
systemProperty 'databaseAdminUser', databaseAdminUser
systemProperty 'databaseAdminPassword', databaseAdminPassword
systemProperty 'databaseType', databaseType
systemProperty 'org.slf4j.simpleLogger.showDateTime', true
systemProperty 'org.slf4j.simpleLogger.dateTimeFormat', 'yyyy-MM-dd HH:mm:ss:SSS Z'
shouldRunAfter tasks.named('test', Test)
}
}
tasks.register('createSBOMZip', Zip) {
description = 'Create SBOM zip file for release'
group = 'documentation'
String sourceDestFolder = buildDir.toString() + "/archive/SBOM/"
archiveFileName = "${project.name}-SBOM-${project.version}.zip"
subprojects.each {
if (it.toString().contains(":applications:workers:release:")) {
String srcPath = it.buildDir.toString() + "/reports/SBOM/"
it.copy{
from srcPath
into sourceDestFolder
}
}
}
from sourceDestFolder
destinationDirectory = (file(buildDir.toString() + "/archive/corda-runtime-os-SBOM/"))
}
if (project.hasProperty('generateSBOM')) {
publishing {
publications {
sbom(MavenPublication) {
artifact createSBOMZip
artifactId "${project.name}-sbom"
groupId 'net.corda'
}
}
}
artifactoryPublish {
publications('sbom')
}
}
// Ensure that we both compile and run using Kotlin OSGi bundles.
// We must ONLY invoke this for Kotlin's classpath configurations.
void configureKotlinForOSGi(Configuration configuration) {
configuration.resolutionStrategy {
dependencySubstitution {
substitute module('org.jetbrains.kotlin:kotlin-stdlib-jdk8') using module("org.jetbrains.kotlin:kotlin-osgi-bundle:${libs.versions.kotlinVersion.get()}")
substitute module('org.jetbrains.kotlin:kotlin-stdlib-jdk7') using module("org.jetbrains.kotlin:kotlin-osgi-bundle:${libs.versions.kotlinVersion.get()}")
substitute module('org.jetbrains.kotlin:kotlin-stdlib-common') using module("org.jetbrains.kotlin:kotlin-osgi-bundle:${libs.versions.kotlinVersion.get()}")
substitute module('org.jetbrains.kotlin:kotlin-stdlib') using module("org.jetbrains.kotlin:kotlin-osgi-bundle:${libs.versions.kotlinVersion.get()}")
substitute module('org.jetbrains.kotlin:kotlin-reflect') using module("org.jetbrains.kotlin:kotlin-osgi-bundle:${libs.versions.kotlinVersion.get()}")
}
}
}
logger.quiet("********************** CORDA 5 OS BUILD **********************")
if (!JavaVersion.current().isCompatibleWith(javaVersion)) {
throw new GradleException("The java version used ${JavaVersion.current()} is not compatible with the expected version ${javaVersion}.")
}
logger.quiet("SDK version: {}", JavaVersion.current())
logger.quiet("JAVA HOME {}", System.getProperty("java.home"))
if (System.getenv("RELEASE_VERSION")?.trim()) {
version = System.getenv("RELEASE_VERSION")
} else {
def versionSuffix = '-SNAPSHOT'
if(project.hasProperty('overridePublishVersionSuffix')) {
versionSuffix = project.property('overridePublishVersionSuffix')
} else if (System.getenv('VERSION_SUFFIX')) {
versionSuffix = System.getenv('VERSION_SUFFIX')
}
version = "$cordaProductVersion.$cordaRuntimeRevision$versionSuffix"
}
logger.quiet("Corda runtime OS release version: {}", version)
logger.quiet("Corda API dependency version spec: {}", cordaApiVersion)
//logger.quiet("Release Type: {}", releaseType)
if ("${compositeBuild}".toBoolean() && file("${cordaApiLocation}").exists()) {
logger.quiet( "Corda-Api project exists on disk in the expected location and Gradle composite build is enabled, corda-api binaries will be substituted with source code")
}
subprojects {
buildscript {
configurations.classpath {
// FORCE Gradle to use latest dynamic-version plugins.
resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
}
}
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'kotlin-allopen'
apply plugin: 'kotlin-jpa'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'jacoco'
version rootProject.version
group 'net.corda'
idea{
module {
downloadJavadoc = true
downloadSources = true
}
}
// we do this to allow for Gradle task caching. OSGI attribute Bnd-LastModified breaks gradle caching as it is a timestamp
// below block tells Gradle to ignore specifically the Bnd-LastModified attribute of the manifest when checking if
// a task is up-to-date, this has no impact on publishing or production of jar.
normalization {
runtimeClasspath {
metaInf {
ignoreCompletely()
}
}
}
pluginManager.withPlugin('io.gitlab.arturbosch.detekt'){
dependencies {
detekt "io.gitlab.arturbosch.detekt:detekt-cli:$detektPluginVersion"
}
}
tasks.named("detekt").configure {
setSource(files("src/main/kotlin", "src/test/kotlin", "src/integrationTest/kotlin", "src/smokeTest/kotlin"))
if(file("$projectDir/detekt-baseline.xml").exists()){
baseline = file("$projectDir/detekt-baseline.xml")
}
var configFiles = files("$rootDir/detekt-config.yml")
if (it.project.getProperties().getOrDefault('cordaEnableFormatting', false) == true) {
configFiles += "$rootDir/detekt-formatting.yaml"
autoCorrect = true
}
config.setFrom(configFiles)
parallel = true
reports {
xml{
outputLocation.set(file("$projectDir/build/detekt-report.xml"))
}
txt.required.set(false)
sarif.required.set(false)
html.required.set(false)
}
}
dependencies {
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$detektPluginVersion"
}
tasks.register("allDependencyInsight", DependencyInsightReportTask) {}
tasks.register("allDependencies", DependencyReportTask) {}
tasks.register('releasableArtifacts') {
description = "Prints a list of all modules which will be released externally"
group = "Release"
if (project.hasProperty('releasable') && project.releasable.toBoolean()) {
logArtifacts(project)
}
}
tasks.register('unReleasableArtifacts') {
description = "Prints a list of all modules which will not be released externally"
group = "Release"
if (!project.hasProperty('releasable') || !project.releasable.toBoolean()) {
logArtifacts(project)
}
}
configurations.configureEach {
resolutionStrategy {
// FORCE Gradle to use latest dynamic versions.
cacheDynamicVersionsFor 0, 'seconds'
// FORCE Gradle to use latest SNAPSHOT versions.
cacheChangingModulesFor 0, 'seconds'
dependencySubstitution {
substitute module("org.dom4j:dom4j") using module("org.apache.servicemix.bundles:org.apache.servicemix.bundles.dom4j:$dom4jOsgiVersion")
}
}
}
allOpen {
annotations(
"javax.persistence.Entity",
"javax.persistence.Embeddable",
"javax.persistence.MappedSuperclass"
)
}
}
// helper to log artifacts we will or will not publish during a release process
def logArtifacts(Project project) {
project.publishing.publications.each { publication ->
logger.info("\n${publication.groupId}:${publication.artifactId}:${publication.version} [${project.path}]")
publication.artifacts.each { artifact ->
logger.info(" * ${artifact.file.name}")
}
}
}
// report updatable dependencies: gradle dependencyUpdates
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}
tasks.named("dependencyUpdates").configure {
rejectVersionIf {
isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)
}
}