This repository has been archived by the owner on Apr 23, 2019. It is now read-only.
/
build.gradle
528 lines (447 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
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
import java.util.regex.Pattern
import net.ltgt.gradle.errorprone.CheckSeverity
buildscript {
repositories {
maven { url 'https://consensys.bintray.com/consensys/' }
jcenter()
}
}
plugins {
id 'com.diffplug.gradle.spotless' version '3.16.0'
id 'net.ltgt.errorprone' version '0.6'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
id 'com.github.hierynomus.license' version '0.15.0'
id 'com.jfrog.bintray' version '1.8.3'
id 'org.jetbrains.kotlin.jvm' version '1.3.20'
id 'org.jetbrains.dokka' version '0.9.17'
}
description = 'A set of libraries and other tools to aid development of blockchain and other decentralized software in Java and other JVM languages'
//////
// Sanity checks
if (!file("${rootDir}/eth-reference-tests/src/test/resources/tests/README.md").exists()) {
throw new GradleException("eth-reference-tests/src/test/resources/tests/README.md missing: please clone submodules (git submodule update --init --recursive)")
}
if (!file("${rootDir}/eth-reference-tests/src/test/resources/eth2.0-tests/README.md").exists()) {
throw new GradleException("eth-reference-tests/src/test/resources/eth2.0-tests/README.md missing: please clone submodules (git submodule update --init --recursive)")
}
//////
// Version numbering
def versionNumber = '1.0.0'
def buildVersion = versionNumber + buildTag()
static String buildTag() {
if (System.getenv('BUILD_RELEASE') == 'true') {
return ''
}
if (System.getenv('CIRCLECI')) {
def buildNumber = System.getenv('CIRCLE_SHA1').take(4).toUpperCase() +
String.format('%02X', System.getenv('CIRCLE_BUILD_NUM').toInteger() % 256, 16)
return '-' + buildNumber + '-snapshot'
}
return '-dev'
}
//////
// Default tasks and build aliases
defaultTasks 'checkLicenses', 'spotlessCheck', 'jar', 'test', ':javadoc'
def buildAliases = ['dev': [
'spotlessApply',
'checkLicenses',
':jar',
'test',
':javadoc'
]]
def expandedTaskList = []
gradle.startParameter.taskNames.each {
expandedTaskList << (buildAliases[it] ? buildAliases[it] : it)
}
gradle.startParameter.taskNames = expandedTaskList.flatten()
//////
// Gradle script formatting
spotless {
groovyGradle {
target '**/*.gradle'
greclipse().configFile(rootProject.file('gradle/greclipse-gradle-consensys-style.properties'))
endWithNewline()
}
}
subprojects {
//////
// Source formatting
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
java {
target project.fileTree(project.projectDir) {
include '**/*.java'
exclude '**/generated-src/**/*.*'
}
removeUnusedImports()
licenseHeaderFile rootProject.file('gradle/spotless.license.java')
eclipse().configFile(rootProject.file('gradle/eclipse-java-consensys-style.xml'))
importOrder 'net.consensys', 'java', ''
endWithNewline()
}
kotlin {
licenseHeaderFile rootProject.file('gradle/spotless.license.java')
ktlint().userData(['indent_size': '2', 'continuation_indent_size' : '2', 'max_line_length': '120'])
endWithNewline()
}
}
//////
// Parallel build execution
tasks.withType(Test) {
// If GRADLE_MAX_TEST_FORKS is not set, use half the available processors
maxParallelForks = (System.getenv('GRADLE_MAX_TEST_FORKS') ?:
(Runtime.runtime.availableProcessors().intdiv(2) ?: 1)).toInteger()
}
tasks.withType(JavaCompile) {
options.fork = true
options.incremental = true
options.encoding = 'UTF-8'
}
task allDependencies(type: DependencyReportTask) {}
}
//////
// Top-level target for deploy (bintrayUpload depends on it)
task deploy() {}
configurations.archives.artifacts.removeAll { PublishArtifact publishArtifact ->
(publishArtifact.type == 'jar' && publishArtifact.name == 'cava')}
//////
// Project defaults
allprojects {
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'signing'
apply from: "${rootDir}/dependency-versions.gradle"
apply from: "${rootDir}/gradle/check-licenses.gradle"
version = buildVersion
repositories { jcenter() }
//////
// Compiler arguments
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
jacoco { toolVersion = '0.8.2' }
dependencies {
errorprone 'com.google.errorprone:error_prone_core'
if (JavaVersion.current().isJava8()) {
errorproneJavac("com.google.errorprone:javac")
}
}
tasks.withType(JavaCompile) {
// Until https://github.com/gradle/gradle/issues/2510 is resolved and
// something like a `releaseCompability` property is added, we have to add
// the --release flag explicitly
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
options.compilerArgs.addAll(['--release', '8'])
}
options.compilerArgs += [
'-Xlint:unchecked',
'-Xlint:cast',
'-Xlint:rawtypes',
'-Xlint:overloads',
'-Xlint:divzero',
'-Xlint:finally',
'-Xlint:static',
'-Werror'
]
options.errorprone {
excludedPaths '.*/generated-src/.*'
check('FutureReturnValueIgnored', CheckSeverity.OFF)
check('UnnecessaryParentheses', CheckSeverity.OFF)
disableWarningsInGeneratedCode = true
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
allWarningsAsErrors = true
freeCompilerArgs = [
'-Xjsr305=strict',
'-Xjvm-default=enable',
'-Xuse-experimental=kotlin.Experimental'
]
}
}
//////
// Use JUnit5 for testing
test { useJUnitPlatform() { includeEngines 'spek', 'junit-jupiter' } }
//////
// Documentation
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/docs/dokka"
jdkVersion = 8
includeNonPublic = false
def relativePath = rootDir.toPath().relativize(projectDir.toPath()).toString()
linkMapping {
dir = projectDir.toString()
url = "https://github.com/consensys/cava/blob/master/$relativePath"
suffix = "#L"
}
}
//////
// Artifact locations
jar {
destinationDir = file("${rootProject.buildDir}/libs")
}
task sourcesJar(type: Jar, dependsOn: classes) {
destinationDir = file("${rootProject.buildDir}/src")
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
destinationDir = file("${rootProject.buildDir}/docs")
classifier = 'javadoc'
from javadoc.destinationDir
}
task dokkaJar(type: Jar, dependsOn: dokka) {
destinationDir = file("${rootProject.buildDir}/docs")
classifier = 'dokka'
from dokka.outputDirectory
}
//////
// Packaging and deployment
tasks.withType(Jar) {
if (rootProject == project) {
baseName = project.name
} else {
baseName = rootProject.name + '-' + project.name
}
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
}
}
if (project.name != 'eth-reference-tests') {
artifacts {
if (project != rootProject) {
archives jar
archives sourcesJar
}
archives dokkaJar
}
signing {
useGpgCmd()
sign configurations.archives
}
publishing {
publications {
MavenDeployment(MavenPublication) { publication ->
if (project != rootProject) {
from components.java
artifact sourcesJar { classifier 'sources' }
}
artifact dokkaJar { classifier 'javadoc' }
groupId 'net.consensys.cava'
artifactId project.jar.baseName
version project.version
pom {
name = project.jar.baseName
afterEvaluate { description = project.description }
url = 'https://github.com/ConsenSys/cava'
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = 'scm:https://github.com/ConsenSys/cava.git'
developerConnection = 'scm:git@github.com:ConsenSys/cava.git'
url = 'https://github.com/ConsenSys/cava'
}
developers {
developer {
name = 'Chris Leishman'
email = 'chris@leishman.org'
organization = 'ConsenSys'
organizationUrl = 'https://www.consensys.net'
}
developer {
name = 'Antoine Toulme'
email = 'antoine@lunar-ocean.com'
organization = 'ConsenSys'
organizationUrl = 'https://www.consensys.net'
}
}
}
pom.withXml {
// use inline versions rather than pom dependency management
asNode().remove(asNode().dependencyManagement[0])
def dependenciesNode = asNode().appendNode('dependencies')
def addDependencyNode = { dep, optional ->
def dependencyNode = dependenciesNode.appendNode('dependency')
if (dep instanceof ProjectDependency) {
dependencyNode.appendNode('groupId', 'net.consensys.cava')
dependencyNode.appendNode('artifactId', rootProject.name + '-' + dep.name)
dependencyNode.appendNode('version', dep.version)
} else {
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
if (dep.version != null) {
dependencyNode.appendNode('version', dep.version)
} else {
def version = dependencyManagement.managedVersions["$dep.group:$dep.name"]
dependencyNode.appendNode('version', version)
}
}
if (optional) {
dependencyNode.appendNode('optional', 'true')
}
def ers = dep.excludeRules
if (!ers.empty) {
def exclusionsNode = dependencyNode.appendNode('exclusions')
ers.each { er ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', er.group)
exclusionNode.appendNode('artifactId', er.module)
}
}
}
configurations.compile.allDependencies.each { dep ->
addDependencyNode(dep, false)
}
configurations.compileOnly.allDependencies.each { dep ->
addDependencyNode(dep, true)
}
if (System.getenv('ENABLE_SIGNING') == 'true') {
def pomFile = file("${project.buildDir}/generated-pom.xml")
writeTo(pomFile)
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
artifact(pomAscFile) {
classifier = null
extension = 'pom.asc'
}
}
}
if (System.getenv('ENABLE_SIGNING') == 'true') {
// create the signed artifacts
tasks.signArchives.signatureFiles.each {
artifact(it) {
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
if (matcher.find()) {
classifier = matcher.group(1)
} else {
classifier = null
}
extension = 'jar.asc'
}
}
}
}
}
}
tasks.withType(Sign) {
onlyIf {
System.getenv('ENABLE_SIGNING') == 'true'
}
}
model {
tasks.generatePomFileForMavenDeploymentPublication {
destination = file("$buildDir/generated-pom.xml")
}
tasks.publishMavenDeploymentPublicationToMavenLocal { dependsOn project.tasks.signArchives }
}
def artifactIdMatcher = Pattern.compile("(.*)-\\d.*")
bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publications = ['MavenDeployment']
filesSpec {
project.extensions.getByType(PublishingExtension).publications.all { publication ->
publication.getArtifacts().all {
def ascFile = new File(it.file.getParentFile(), it.file.getName() + '.asc')
if (ascFile.exists()) {
def matcher = artifactIdMatcher.matcher(it.file.getName())
matcher.find()
def artifactId = matcher.group(1)
from ascFile.getAbsolutePath()
into publication.groupId.replaceAll('\\.', '/') + '/' + artifactId + '/' + publication.version + '/'
}
}
}
}
dryRun = !(System.getenv('BINTRAY_DEPLOY') == 'true')
publish = true
pkg {
repo = 'consensys'
name = 'cava'
userOrg = 'consensys'
licenses = ['Apache-2.0']
version {
name = project.version
desc = 'Cava distribution'
released = new Date()
vcsTag = project.version
}
}
}
deploy.dependsOn bintrayUpload
}
}
//////
// Configure root project as a virtual package that depends on all components
dependencies {
subprojects.each { p ->
switch (p.name) {
case 'eth-reference-tests':
// ignore
break
case 'crypto':
compile(p) {
exclude group: 'com.github.jnr', module: 'jnr-ffi'
}
break
default:
compile p
break
}
}
}
jar { enabled = false }
javadoc {
subprojects.each {
source += it.javadoc.source
classpath += it.javadoc.classpath
}
}
dokka {
moduleName = rootProject.name
subprojects.each {
dependsOn it.classes
it.sourceSets.main.output.each { d ->
if (d.exists()) {
classpath += d
}
}
}
sourceDirs = files(subprojects.collect {
return [
new File(it.projectDir, '/src/main/kotlin'),
new File(it.projectDir, '/src/main/java')
]
})
linkMapping {
dir = rootDir.toString()
url = "https://github.com/consensys/cava/blob/master"
suffix = "#L"
}
includes = ['PACKAGES.md']
externalDocumentationLink {
url = new URL("https://docs.oracle.com/javase/8/docs/api/")
}
externalDocumentationLink {
url = new URL('https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/')
}
}
dokkaJar {
baseName = rootProject.name
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
}
}