forked from real-logic/agrona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
573 lines (485 loc) · 17.2 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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
/*
* Copyright 2014-2024 Real Logic Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'org.ow2.asm:asm:9.7'
classpath 'org.ow2.asm:asm-commons:9.7'
}
}
plugins {
id 'java-library'
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'biz.aQute.bnd.builder' version '6.4.0' apply false
id 'com.github.ben-manes.versions' version '0.51.0'
}
defaultTasks 'clean', 'build'
static def getBuildJavaVersion() {
def buildJavaVersion = System.getenv('BUILD_JAVA_VERSION') ?: JavaVersion.current().getMajorVersion()
if (buildJavaVersion.indexOf('.') > 0) {
buildJavaVersion = buildJavaVersion.substring(0, buildJavaVersion.indexOf('.'))
}
if (buildJavaVersion.indexOf('-') > 0) {
buildJavaVersion = buildJavaVersion.substring(0, buildJavaVersion.indexOf('-'))
}
Integer.parseInt(buildJavaVersion)
}
int buildJavaVersion = getBuildJavaVersion()
def toolchainLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(buildJavaVersion)
}
def toolchainCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(buildJavaVersion)
}
def toolchainJavadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(buildJavaVersion)
}
def byteBuddyVersion = '1.14.18'
def findbugsAnnotationsVersion = '3.0.1'
def checkstyleVersion = '9.3'
def hamcrestVersion = '2.2'
def mockitoVersion = '4.11.0'
def junitVersion = '5.10.3'
def guavaTestLib = '33.2.1-jre'
def junit4Version = '4.13.2'
def jmhVersion = '1.37'
def jcstressVersion = '0.16'
def agronaGroup = 'org.agrona'
def agronaVersion = '1.22.0-SNAPSHOT'
def getConfigProperty(final String projectPropertyName, final String envVarName) {
String value = project.findProperty(projectPropertyName)
if (!value) {
value = System.getenv(envVarName)
if (!value) {
return null
}
}
value = value.trim()
return value ? value : null
}
ext {
isReleaseVersion = !agronaVersion.endsWith('-SNAPSHOT')
ossrhReleasesRepoUrl = 'http://localhost:8081/artifactory'
ossrhSnapshotsRepoUrl = 'http://localhost:8081/artifactory'
ossrhUsername = 'admin'
ossrhPassword = 'password'
signingKey = getConfigProperty('signingKey', 'SIGNING_GPG_SECRET_KEY') // NOTE: ASCII armored secret key
signingPassword = getConfigProperty('signingPassword', 'SIGNING_GPG_PASSWORD') // NOTE: Plain text
}
def projectPom = {
name = 'agrona'
// optionally artifactId can be defined here
description = 'High performance primitives and utility library.'
url = 'https://github.com/real-logic/agrona'
scm {
connection = 'scm:git:https://github.com/real-logic/agrona.git'
developerConnection = 'scm:git:https://github.com/real-logic/agrona.git'
url = 'https://github.com/real-logic/agrona.git'
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'tmontgomery'
name = 'Todd L. Montgomery'
email = '[email protected]'
url = 'https://github.com/tmontgomery'
}
developer {
id = 'mjpt777'
name = 'Martin Thompson'
email = '[email protected]'
url = 'https://github.com/mjpt777'
}
developer {
id = 'RichardWarburton'
name = 'Richard Warburton'
email = '[email protected]'
url = 'https://github.com/RichardWarburton'
}
developer {
id = 'nitsanw'
name = 'Nitsan Wakart'
email = '[email protected]'
url = 'https://github.com/nitsanw'
}
developer {
id = 'mikeb01'
name = 'Mike Barker'
email = '[email protected]'
url = 'https://github.com/mikeb01'
}
developer {
id = 'vyazelenko'
name = 'Dmytro Vyazelenko'
email = '[email protected]'
url = 'https://github.com/vyazelenko'
}
}
}
allprojects {
repositories {
mavenCentral()
}
configurations.configureEach {
resolutionStrategy {
failOnVersionConflict()
force "junit:junit:${junit4Version}",
"net.bytebuddy:byte-buddy:${byteBuddyVersion}",
"net.bytebuddy:byte-buddy-agent:${byteBuddyVersion}"
}
}
tasks.withType(JavaExec).configureEach {
javaLauncher.set(toolchainLauncher)
}
}
jar.enabled = false
subprojects {
apply plugin: 'java-library'
apply plugin: 'checkstyle'
group = agronaGroup
version = agronaVersion
checkstyle.toolVersion = "${checkstyleVersion}"
tasks.withType(Sign).configureEach {
onlyIf {
isReleaseVersion && gradle.taskGraph.hasTask(tasks.publish)
}
}
tasks.withType(Jar).configureEach {
enabled = true
includeEmptyDirs = false
}
tasks.withType(JavaCompile).configureEach {
doFirst {
mkdir 'build/resources/main' // Avoid Javac warning about non-existing directory
}
if (buildJavaVersion >= 9) {
javaCompiler.set(toolchainCompiler)
} else {
options.fork = true
def javaHome = toolchainCompiler.get().metadata.installationPath.asFile.toPath().toAbsolutePath()
options.forkOptions.javaHome = javaHome.toFile()
}
options.compilerArgs.addAll(['-Xlint:all', '-Werror']) // Enable all warnings and treat them as errors
options.compilerArgs.add('-XDignore.symbol.file') // Suppress warnings about using Unsafe
options.encoding = 'UTF-8'
options.deprecation = true
}
test {
if (buildJavaVersion >= 9) {
jvmArgs('--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED')
}
if (buildJavaVersion >= 21) {
jvmArgs('-XX:+EnableDynamicAgentLoading')
}
if (buildJavaVersion >= 23) {
jvmArgs('--sun-misc-unsafe-memory-access=allow')
}
useJUnitPlatform()
testLogging {
for (def level : LogLevel.values())
{
def testLogging = get(level)
testLogging.exceptionFormat = 'full'
testLogging.events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
}
}
systemProperties(
'agrona.disable.bounds.checks': 'false',
'agrona.strict.alignment.checks': 'true',
'net.bytebuddy.experimental': 'true')
javaLauncher.set(toolchainLauncher)
}
javadoc {
title = '<h1>Agrona</h1>'
options.bottom = '<i>Copyright © 2014-2024 Real Logic Limited. All Rights Reserved.</i>'
options.encoding = 'UTF-8'
options.docEncoding = 'UTF-8'
options.charSet = 'UTF-8'
if (buildJavaVersion > 22) { // early access JavaDoc location is different
options.links("https://download.java.net/java/early_access/jdk${buildJavaVersion}/docs/api/")
}
else if (buildJavaVersion >= 11) {
options.links("https://docs.oracle.com/en/java/javase/${buildJavaVersion}/docs/api/")
}
else {
options.links("https://docs.oracle.com/javase/${buildJavaVersion}/docs/api/")
}
if (buildJavaVersion >= 10) {
options.addBooleanOption 'html5', true
}
javadocTool.set(toolchainJavadocTool)
}
}
project(':agrona') {
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'biz.aQute.bnd.builder'
dependencies {
testImplementation files('build/classes/java/generated')
testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
testImplementation "org.mockito:mockito-inline:${mockitoVersion}"
testImplementation "com.google.guava:guava-testlib:${guavaTestLib}"
testImplementation "junit:junit:${junit4Version}" // Compatibility with JUnit 4
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junitVersion}"
}
def generatedDir = file("${buildDir}/generated-src")
sourceSets {
generated {
java.srcDir generatedDir
compileClasspath += sourceSets.main.runtimeClasspath
}
}
tasks.register('generatePrimitiveSpecialisations', JavaExec) {
mainClass.set('org.agrona.generation.SpecialisationGenerator')
classpath = sourceSets.main.runtimeClasspath
outputs.dir generatedDir
}
compileGeneratedJava.dependsOn generatePrimitiveSpecialisations
compileTestJava.dependsOn compileGeneratedJava
javadoc.dependsOn generatePrimitiveSpecialisations
jar {
from sourceSets.generated.output
bundle {
bnd """
Automatic-Module-Name: org.agrona.core
Bundle-Name: org.agrona.core
Bundle-SymbolicName: org.agrona.core
Implementation-Title: Agrona
Implementation-Vendor: Real Logic Limited
Implementation-Version: ${agronaVersion}
-exportcontents: org.agrona, org.agrona.*
# Suppress headers that reduce reproducibility.
-reproducible: true
-noextraheaders: true
"""
}
}
tasks.register('sourcesJar', Jar) {
dependsOn generatePrimitiveSpecialisations
archiveClassifier.set('sources')
from sourceSets.main.allSource
from sourceSets.generated.allSource
}
javadoc {
source += sourceSets.generated.allJava
}
java {
withSourcesJar()
withJavadocJar()
}
publishing {
publications {
agrona(MavenPublication) {
from components.java
pom(projectPom)
}
}
repositories {
maven {
name = 'MavenCentral'
allowInsecureProtocol = true
url(!isReleaseVersion ? ossrhSnapshotsRepoUrl : ossrhReleasesRepoUrl)
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
}
signing {
if (null != signingKey) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign publishing.publications.agrona
}
}
project(':agrona-agent') {
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.github.johnrengelman.shadow'
dependencies {
implementation project(':agrona')
implementation "net.bytebuddy:byte-buddy:${byteBuddyVersion}"
// Avoid Javac warning about missing dependency from ByteBuddy
compileOnly "com.google.code.findbugs:findbugs-annotations:${findbugsAnnotationsVersion}"
testCompileOnly "com.google.code.findbugs:findbugs-annotations:${findbugsAnnotationsVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testImplementation "net.bytebuddy:byte-buddy-agent:${byteBuddyVersion}"
}
shadowJar {
archiveClassifier.set('')
manifest.attributes(
'Implementation-Title': 'Agrona',
'Implementation-Version': agronaVersion,
'Implementation-Vendor': 'Real Logic Limited',
'Premain-Class': 'org.agrona.agent.BufferAlignmentAgent',
'Agent-Class': 'org.agrona.agent.BufferAlignmentAgent',
'Can-Redefine-Classes': 'true',
'Can-Retransform-Classes': 'true',
'Automatic-Module-Name': 'org.agrona.agent'
)
relocate 'net.bytebuddy', 'org.agrona.shadow.net.bytebuddy'
}
jar.finalizedBy shadowJar
tasks.register('sourcesJar', Jar) {
dependsOn ':agrona:generatePrimitiveSpecialisations'
archiveClassifier.set('sources')
from sourceSets.main.allSource
from project(':agrona').sourceSets.main.allSource
from project(':agrona').sourceSets.generated.allSource
}
javadoc {
source += sourceSets.main.allJava
source += project(':agrona').sourceSets.main.allJava
source += project(':agrona').sourceSets.generated.allJava
}
javadoc.dependsOn ':agrona:generatePrimitiveSpecialisations'
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
publishing {
publications {
agronaAgent(MavenPublication) {
artifact shadowJar
artifact sourcesJar
artifact javadocJar
pom(projectPom)
}
}
repositories {
maven {
name = 'MavenCentral'
allowInsecureProtocol = true
url(!isReleaseVersion ? ossrhSnapshotsRepoUrl : ossrhReleasesRepoUrl)
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
}
signing {
if (null != signingKey)
{
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign publishing.publications.agronaAgent
}
}
project(':agrona-benchmarks') {
apply plugin: 'com.github.johnrengelman.shadow'
dependencies {
implementation "org.openjdk.jmh:jmh-core:${jmhVersion}"
annotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:${jmhVersion}"
implementation project(':agrona')
}
shadowJar {
archiveFileName = 'benchmarks.jar'
archiveClassifier.set('benchmarks')
manifest.attributes('Main-Class': 'org.openjdk.jmh.Main')
}
jar.finalizedBy shadowJar
}
project(':agrona-concurrency-tests') {
apply plugin: 'com.github.johnrengelman.shadow'
dependencies {
annotationProcessor "org.openjdk.jcstress:jcstress-core:${jcstressVersion}"
implementation "org.openjdk.jcstress:jcstress-core:${jcstressVersion}"
implementation project(':agrona')
}
compileJava {
if (11 == buildJavaVersion) {
options.compilerArgs.add('-Xlint:-processing')
}
}
shadowJar {
archiveFileName = 'concurrency-tests.jar'
archiveClassifier.set('concurrency-tests')
manifest.attributes('Main-Class': 'org.openjdk.jcstress.Main')
}
jar.finalizedBy shadowJar
tasks.register('concurrencyTests', JavaExec) {
dependsOn shadowJar
classpath = files(tasks.shadowJar)
workingDir = project.buildDir
args = ['-jvmArgs', '-Dagrona.disable.bounds.checks=true -Dagrona.strict.alignment.checks=true -XX:+UseParallelGC', '-r', 'reports/jcstress']
standardOutput = new NullOutputStream()
errorOutput = new NullOutputStream()
}
def jcstressResults = project.hasProperty('jcstress-results') ? project.getProperty('jcstress-results') : ''
tasks.register('parseResultsFile', JavaExec) {
dependsOn shadowJar
group 'verification'
classpath = files(tasks.shadowJar)
workingDir = project.buildDir
args = ['-p', jcstressResults, '-r', 'reports/jcstress']
}
}
tasks.register('testReport', TestReport) {
destinationDirectory = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
testResults.setFrom(subprojects*.test)
}
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r|-jre)?$/
return !stableKeyword && !(version ==~ regex)
}
tasks.named("dependencyUpdates").configure {
// Reject all non stable versions
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
tasks.register('copyTestLogs', Copy) {
from '.'
include '**/*.log'
include '**/jcstress-results-*.gz'
include 'LICENSE'
exclude 'build'
into 'build/test_logs'
includeEmptyDirs = false
}
wrapper {
gradleVersion = '8.1.1'
distributionType = 'ALL'
}
class NullOutputStream extends OutputStream
{
void write(final int bytes) throws IOException
{
}
void write(final byte[] bytes) throws IOException
{
}
void write(final byte[] bytes, final int offset, final int length) throws IOException
{
}
}