-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.gradle
388 lines (339 loc) · 13.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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import static org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
import static org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_8
import static org.gradle.api.JavaVersion.VERSION_17
import static org.gradle.jvm.toolchain.JavaLanguageVersion.of
import org.jetbrains.dokka.gradle.DokkaTask
buildscript {
ext {
vcsUrl = System.getenv('GIT_URL') ?: 'https://github.com/corda/corda-api.git'
}
}
plugins {
id 'net.corda.cordapp.cordapp-configuration'
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
alias libs.plugins.snyk
alias libs.plugins.grgit // used for GIT interaction (e.g. extract commit hash)
id 'corda.root-publish'
id 'jacoco' // test coverage
alias libs.plugins.task.tree // utility to visualise Gradle task DAG
alias libs.plugins.dokka
alias libs.plugins.dependency.check.versions // discover possible dependency version upgrades
alias libs.plugins.cyclonedx.bom apply false
alias libs.plugins.sonar
}
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"
}
}
def revision = {
if (System.getenv("CORDA_REVISION")) {
return System.getenv("CORDA_REVISION")
}
try {
return "git rev-parse HEAD".execute().text.trim()
} catch (Exception error) {
logger.warn("git is unavailable in build environment", error)
"unknown"
}
}()
// 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()}")
}
}
}
def releaseType = System.getenv('RELEASE_TYPE') ?: "SNAPSHOT"
def javaVersion = VERSION_17
logger.quiet("********************** CORDA 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"))
def cordaVersion = "$cordaProductVersion.$cordaApiRevision"
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 = "$cordaVersion$versionSuffix"
}
logger.quiet("Corda release version: {}", version)
logger.quiet("Corda baseVersion: {}", cordaVersion)
logger.quiet("Release Type: {}", releaseType)
subprojects {
buildscript {
configurations.classpath {
// FORCE Gradle to use latest SNAPSHOT plugins.
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
ext {
releasable = true // all corda-api jars are externally consumable
}
// NOTE: according to this we shouldn't be using subprojects:
// https://discuss.gradle.org/t/apply-plugin-with-version-catalog/43029
apply plugin: libs.plugins.cyclonedx.bom.get().pluginId
cyclonedxBom {
includeConfigs = ["runtimeClasspath"]
skipProjects = [rootProject.name]
destination = file("${buildDir}/reports/SBOM")
outputName = "${project.name}-corda-api-sbom"
}
version rootProject.version
group 'net.corda'
pluginManager.withPlugin('java') {
apply plugin: 'org.sonarqube'
java {
toolchain {
languageVersion = of(javaVersion.majorVersion.toInteger())
}
withSourcesJar()
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-parameters'
options.encoding = 'UTF-8'
options.release.set(11)
}
// Added to support junit5 tests
tasks.withType(Test).configureEach {
useJUnitPlatform {
excludeTags project.hasProperty('runUnstableTests') ? 'runAllTestsNoExclusions' : 'Unstable'
}
doFirst {
// Create all temporary files within the build directory.
systemProperty 'java.io.tmpdir', buildDir.absolutePath
}
retry {
if (System.getenv().containsKey("JENKINS_URL")) {
maxRetries = 2
maxFailures = 10
}
}
}
}
pluginManager.withPlugin('org.jetbrains.kotlin.jvm') {
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'jacoco'
apply plugin: 'org.jetbrains.dokka'
// NOTE: question whether it is "ok" to force dependencies on all modules like this
// thinking is that for the test dependencies it's ok as it'll keep things consistent.
// we can add exclusions, or review this if necessary.
dependencies {
detektPlugins libs.detekt.formatting
}
// Making all persistence entity open and with an empty constructor to allow Hibernate to work.
apply plugin: 'kotlin-allopen'
allOpen {
annotations(
"javax.persistence.Entity",
"javax.persistence.Embeddable",
"javax.persistence.MappedSuperclass"
)
}
apply plugin: 'kotlin-jpa'
configurations {
[ compileClasspath, testCompileClasspath, runtimeClasspath, testRuntimeClasspath ].forEach { cfg ->
configureKotlinForOSGi(cfg)
}
}
tasks.withType(KotlinCompile).configureEach {
compilerOptions {
allWarningsAsErrors = true
languageVersion = KOTLIN_1_8
apiVersion = KOTLIN_1_8
verbose = true
jvmTarget = JVM_11
javaParameters = true // Useful for reflection.
freeCompilerArgs.addAll([
"-Xjvm-default=all"
])
}
}
tasks.named("detekt").configure {
if(file("$projectDir/detekt-baseline.xml").exists()){
baseline = file("$projectDir/detekt-baseline.xml")
}
config.setFrom(files("$rootDir/detekt-config.yml"))
parallel = true
reports {
xml{
outputLocation.set(file("$projectDir/build/detekt-report.xml"))
}
txt.required.set(false)
sarif.required.set(false)
html.required.set(false)
}
}
tasks.named('jacocoTestReport') {
def jacocoExecutionDataFiles = fileTree(buildDir).include("/jacoco/*.exec")
executionData.setFrom(jacocoExecutionDataFiles)
dependsOn tasks.named('test') // tests are required to run before generating the report
reports {
xml.required = true
html.required = true
}
}
tasks.register('javadocJar', Jar) {
description = 'Create JavaDoc Jar from dokka docs'
group = 'documentation'
dependsOn(dokkaHtml)
archiveBaseName = jar.archiveBaseName
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
}
if (project.hasProperty('generateJavaDocWithBuild')) {
artifacts {
archives javadocJar
}
}
tasks.withType(DokkaTask.class).configureEach {
moduleVersion.set(System.getenv("RELEASE_VERSION") ?: cordaVersion)
}
}
// 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()
}
}
}
// TODO: as above, this may not apply to all modules, so maybe should be moved out
tasks.withType(Jar).matching { it.name != 'cpk' && it.name != 'cpb' }.configureEach {
manifest {
attributes("Corda-Release-Version": project.version)
attributes("Corda-Revision": revision)
attributes("Automatic-Module-Name": "net.corda.${project.name.replace('-', '.')}")
// NOTE: this needs to be reverted to a URL with the version once the URL structure has been defined.
// attributes("Corda-Docs-Link": "https://docs.corda.net/docs/corda-os/$cordaVersion")
attributes("Corda-Docs-Link": "https://docs.r3.com/")
}
}
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(KotlinCompile)
}
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)
}
}
}
// helper to log artifacts we will or will not publish during a release process
def logArtifacts(Project project) {
project.publishing.publications.each { publication ->
logger.quiet("\n${publication.groupId}:${publication.artifactId}:${publication.version} [${project.path}]")
publication.artifacts.each { artifact ->
logger.quiet(" * ${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)
}
}
tasks.named("wrapper") {
gradleVersion = '8.4'
distributionType = Wrapper.DistributionType.BIN
}
tasks.register('generateMultiModuleDocs', Zip) {
description = 'Create mutli module docs Site Jar'
group = 'documentation'
dependsOn dokkaJavadocCollector
archiveFileName = "corda-api-docs-${project.version}.zip"
from("${buildDir}/dokka/javadocCollector")
destinationDirectory = (file("$buildDir/corda-api-docs"))
}
tasks.named('dokkaJavadocCollector') {
dependsOn ':data:avro-schema:generateAvro', 'data:avro-schema:generateOSGiPackageInfo'
}
if (project.hasProperty('publishMultiModulekDocs')) {
publishing {
publications {
dokkaDocs(MavenPublication) {
artifact generateMultiModuleDocs
artifactId "corda-api-docs"
groupId 'net.corda'
}
}
}
artifactoryPublish {
publications('dokkaDocs')
}
}
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 {
String srcPath = it.buildDir.toString() + "/reports/SBOM/"
it.copy{
from srcPath
into sourceDestFolder
}
}
from sourceDestFolder
destinationDirectory = (file(buildDir.toString() + "/archive/corda-api-SBOM/"))
}
if (project.hasProperty('generateSBOM')) {
publishing {
publications {
sbom(MavenPublication) {
artifact createSBOMZip
artifactId "${project.name}-sbom"
groupId 'net.corda'
}
}
}
artifactoryPublish {
publications('sbom')
}
}