-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.gradle
407 lines (355 loc) · 14.5 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
/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands).
*
* Licensed under the Radix License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
*
* radixfoundation.org/licenses/LICENSE-v1
*
* The Licensor hereby grants permission for the Canonical version of the Work to be
* published, distributed and used under or by reference to the Licensor’s trademark
* Radix ® and use of any unregistered trade names, logos or get-up.
*
* The Licensor provides the Work (and each Contributor provides its Contributions) on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
*
* Whilst the Work is capable of being deployed, used and adopted (instantiated) to create
* a distributed ledger it is your responsibility to test and validate the code, together
* with all logic and performance of that code under all foreseeable scenarios.
*
* The Licensor does not make or purport to make and hereby excludes liability for all
* and any representation, warranty or undertaking in any form whatsoever, whether express
* or implied, to any entity or person, including any representation, warranty or
* undertaking, as to the functionality security use, value or other characteristics of
* any distributed ledger nor in respect the functioning or value of any tokens which may
* be created stored or transferred using the Work. The Licensor does not warrant that the
* Work or any use of the Work complies with any law or regulation in any territory where
* it may be implemented or used or that it will be appropriate for any specific purpose.
*
* Neither the licensor nor any current or former employees, officers, directors, partners,
* trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor
* shall be liable for any direct or indirect, special, incidental, consequential or other
* losses of any kind, in tort, contract or otherwise (including but not limited to loss
* of revenue, income or profits, or loss of use or data, or loss of reputation, or loss
* of any economic or other opportunity of whatsoever nature or howsoever arising), arising
* out of or in connection with (without limitation of any use, misuse, of any ledger system
* or use made or its functionality or any performance or operation of any code or protocol
* caused by bugs or programming or logic errors or otherwise);
*
* A. any offer, purchase, holding, use, sale, exchange or transmission of any
* cryptographic keys, tokens or assets created, exchanged, stored or arising from any
* interaction with the Work;
*
* B. any failure in a transmission or loss of any token or assets keys or other digital
* artefacts due to errors in transmission;
*
* C. bugs, hacks, logic errors or faults in the Work or any communication;
*
* D. system software or apparatus including but not limited to losses caused by errors
* in holding or transmitting tokens by any third-party;
*
* E. breaches or failure of security including hacker attacks, loss or disclosure of
* password, loss of private key, unauthorised use or misuse of such passwords or keys;
*
* F. any losses including loss of anticipated savings or other benefits resulting from
* use of the Work or any changes to the Work (however implemented).
*
* You are solely responsible for; testing, validating and evaluation of all operation
* logic, functionality, security and appropriateness of using the Work for any commercial
* or non-commercial purpose and for any reproduction or redistribution by You of the
* Work. You assume all risks associated with Your use of the Work and the exercise of
* permissions under this License.
*/
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'distribution'
apply plugin: 'project-report'
apply plugin: 'nebula.ospackage'
apply plugin: 'com.moowork.node'
apply plugin: 'org.sonarqube'
node {
download = true
}
application {
mainClass = 'com.radixdlt.RadixNodeApplication'
applicationDefaultJvmArgs = ["--enable-preview"]
}
startScripts {
classpath = files('src/resources') + classpath
// ^^ will prepend '$APP_HOME/lib/resources' to the classpath, which we'll use it as a pattern below
doLast {
def windowsScriptFile = file getWindowsScript()
def unixScriptFile = file getUnixScript()
windowsScriptFile.text = windowsScriptFile.text.replace('%APP_HOME%\\lib\\resources', '%RADIXDLT_HOME%')
unixScriptFile.text = unixScriptFile.text.replace('$APP_HOME/lib/resources', '$RADIXDLT_HOME')
}
}
sourceSets {
testcore {
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/test-core/java')
}
resources.srcDir file('src/test-core/resources')
}
}
configurations {
testcoreImplementation.extendsFrom testImplementation
}
sourceSets {
test {
java {
compileClasspath += testcore.output
runtimeClasspath += testcore.output
}
}
}
sourceSets {
integration {
java {
compileClasspath += main.output + testcore.output
runtimeClasspath += main.output + testcore.output
srcDir file('src/integration/java')
}
resources.srcDir file('src/integration/resources')
}
}
processIntegrationResources {
// Avoids an issue with the build picking up a duplicate MockMaker
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
configurations {
integrationImplementation.extendsFrom testImplementation
}
task runSteadyStateIntegrationTests(type: Test) {
filter {
includeTestsMatching "com.radixdlt.integration.steady_state.*"
}
testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
// Use half of available processors. A greater number was tried, but the tests either failed or there was no gain in performance.
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
mustRunAfter(test)
}
task runTargetedIntegrationTests(type: Test) {
filter {
includeTestsMatching "com.radixdlt.integration.targeted.*"
}
testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
// We're using all available processors here for now because we want to run all classes at the same time and they don't seem to be cpu intensive
maxParallelForks = Runtime.runtime.availableProcessors()
mustRunAfter(test)
}
task runAllIntegrationTests(type: Test) {
testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
// Use half of available processors. A greater number was tried, but the tests either failed or there was no gain in performance.
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
mustRunAfter(test)
}
task versionFile {
mustRunAfter(processResources)
doLast {
File resourceFolder = new File("$buildDir/resources/main")
if (!resourceFolder.exists()) {
resourceFolder.mkdirs()
}
def versionFile = new File("$resourceFolder", 'version.properties').text = """
VERSION_BRANCH=${getEnvironmentVariable('VERSION_BRANCH')}
VERSION_COMMIT=${getEnvironmentVariable('VERSION_COMMIT')}
VERSION_DISPLAY=${getEnvironmentVariable('VERSION_DISPLAY')}
VERSION_BUILD=${getEnvironmentVariable('VERSION_BUILD')}
VERSION_TAG=${getEnvironmentVariable('VERSION_TAG')}
VERSION_LAST_TAG=${getEnvironmentVariable('VERSION_LAST_TAG')}
"""
}
}
classes {
dependsOn(versionFile)
}
def getEnvironmentVariable(envVarName) {
def versionEnvVar = System.getenv(envVarName)
return (versionEnvVar != null) ? versionEnvVar : ""
}
runAllIntegrationTests {
jacoco {
// We don't want integration tests included in code coverage.
enabled false
}
}
runSteadyStateIntegrationTests {
jacoco {
// We don't want integration tests included in code coverage.
enabled false
}
}
runTargetedIntegrationTests {
jacoco {
// We don't want integration tests included in code coverage.
enabled false
}
}
jacocoTestReport {
dependsOn test
reports {
xml.enabled true
csv.enabled false
}
}
dependencies {
implementation project(':common')
implementation project(':core-rust-bridge')
implementation project(':keygen')
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'io.swagger:swagger-annotations:1.5.0'
implementation "com.github.akarnokd:rxjava3-extensions"
implementation 'io.reactivex.rxjava3:rxjava'
implementation 'com.sleepycat:je'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.lmax:disruptor'
implementation 'commons-cli:commons-cli'
implementation 'org.xerial.snappy:snappy-java'
implementation 'io.netty:netty-all'
implementation 'com.google.inject:guice'
implementation 'com.google.inject.extensions:guice-grapher'
implementation 'io.undertow:undertow-core'
implementation 'com.stijndewitt.undertow.cors:undertow-cors-filter'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
testImplementation project(path: ':common')
testImplementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.mockito:mockito-core'
testImplementation 'junit:junit'
testImplementation 'pl.pragmatists:JUnitParams'
testImplementation 'nl.jqno.equalsverifier:equalsverifier'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.reflections:reflections'
}
// More memory
tasks.withType(JavaExec) {
jvmArgs('-Xmx1024m')
}
tasks.withType(Test){
minHeapSize = "128m"
maxHeapSize = "4096m"
}
// Compress distTar
tasks.withType(Tar) {
compression = Compression.GZIP
}
def debSafeVersionName() {
// project.version comes from radixVersion() in the root gradle property
def safeVersion = project.version
.replaceAll('-', '~') // Debian doesn't like - in the name
.replaceAll(/[^A-Za-z0-9.+~]/, '') // Replace versions that dev doesn't like
// Note - The deb version must start with a number
if (!safeVersion.matches(~/\d.+/)) {
safeVersion = "0~~$safeVersion"
}
return safeVersion
}
def debPackageName() {
return "radixdlt"
}
def debOutputFileName() {
return "${debPackageName()}_${debSafeVersionName()}_all.deb"
}
// https://github.com/nebula-plugins/gradle-ospackage-plugin/wiki/Provided-Plugins#os-package-plugin
ospackage() {
os = LINUX
postInstall file('ospackage/postinst.sh')
preUninstall file('ospackage/prerm.sh')
postUninstall file('ospackage/postrm.sh')
// These should match the scripts in ospackage
def serviceName = debPackageName()
def optDirectory = debPackageName()
from("$buildDir/install/$name") {
into "/opt/$optDirectory"
}
from("ospackage/${serviceName}.service") {
into "/etc/systemd/system"
}
// XXX: This ought to be done somewhere else.
def target = "x86_64-unknown-linux-gnu"
if (System.getProperty("os.arch") == "aarch64") {
target= "aarch64-unknown-linux-gnu"
}
def coreRustBuildType = project.property("rustBinaryBuildType")
from("${project(':core-rust').projectDir}/target/${target}/${coreRustBuildType}/libcorerust.so") {
into "/usr/lib/jni/"
}
// See https://github.com/nebula-plugins/gradle-ospackage-plugin/wiki/Deb-Plugin#basic-usage
buildDeb {
dependsOn += [installDist, ":core-rust:buildRustForDocker"]
version = debSafeVersionName()
packageName = debPackageName()
doLast {
println "SUCCESS: Built deb package: ${debOutputFileName()}"
}
}
buildRpm {
dependsOn += [installDist, ":core-rust:buildRustForDocker"]
}
}
/**
* Display size of each dependency
*/
task depsize {
doLast {
final formatStr = "%,10.2f"
final conf = configurations.default
final size = conf.collect { it.length() / (1024 * 1024) }.sum()
final out = new StringBuffer()
out << 'Total dependencies size:'.padRight(45)
out << "${String.format(formatStr, size)} Mb\n\n"
conf.sort { -it.length() }
.each {
out << "${it.name}".padRight(45)
out << "${String.format(formatStr, (it.length() / 1024))} kb\n"
}
println(out)
}
}
/**
* Copies the *.deb file in the docker directory
*/
task deb4docker(dependsOn: buildDeb) {
doFirst {
def createdDebFileName = debOutputFileName()
def previousDebFileToDeleteRegex = ~/.+_all\.deb/
def builtDebFileLocation = "$buildDir/distributions/$createdDebFileName"
def destinationDir = project.file('../docker')
def destinationLocation = "$destinationDir/$createdDebFileName"
if (!file(builtDebFileLocation).exists()) {
throw new GradleException("Expected to find built deb package at $builtDebFileLocation but it wasn't there - perhaps the replacement regex in deb4docker is broken / needs fixing")
}
println "Built deb package found at: $builtDebFileLocation"
def names = [] as Set
destinationDir.eachFileMatch(groovy.io.FileType.FILES, previousDebFileToDeleteRegex) {
names << it.name
}
names.toSorted().each {
def rip = new File(destinationDir, it)
rip.delete()
println "Deleted previous deb package: ${rip.path}"
}
copy {
from builtDebFileLocation
into destinationDir
}
println "SUCCESS: deb package copied for the docker build to: $destinationLocation"
}
}
// This adds the `startScripts` task artifacts from the keygen subproject (i.e. app
// run scripts: `keygen` and `keygen.bat`) to the "bin" folder in core's distribution.
// Note that we don't need to manually add keygen jars (to "libs") - this is taken care of
// by regular dependency management.
applicationDistribution.from(project(":keygen").getTasksByName("startScripts", false).outputs) {
into "bin"
}
// This ensures that keygen scripts are built (and can be copied over to "bin", see above)
// before we assemble core's packages.
[distZip, distTar]*.mustRunAfter ":keygen:startScripts"