-
Notifications
You must be signed in to change notification settings - Fork 261
/
build.gradle
528 lines (439 loc) · 21.1 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 net.ltgt.gradle.errorprone.CheckSeverity
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins {
id "com.peterabeles.gversion" version "1.10.2" apply false
id "net.ltgt.errorprone" version "2.0.2" apply false
id "com.diffplug.spotless" version "6.9.1" apply false
}
ext.libpath = file('./').absolutePath
allprojects {
apply plugin: 'com.peterabeles.gversion'
apply plugin: 'com.peterabeles.gversion'
group = 'org.boofcv'
version = '1.1.8-SNAPSHOT'
createVersionFile.enabled = false // run only once. enabled in types
}
project.ext.commons_io_version = '2.16.1'
project.ext.deepboof_version = '0.5.2'
project.ext.lombok_version = '1.18.28'
project.ext.jabel_version = '1.0.1-1'
project.ext.guava_version = '33.2.0-jre'
project.ext.args4j_version = '2.33'
project.ext.junit_version = '5.10.0'
project.ext.errorprone_version = '2.21.1'
project.ext.nullaway_version = '0.10.11'
project.ext.auto64to32_version = '3.2.2'
project.ext.snakeyaml_version = '2.3'
project.ext.jmh_version = '1.36'
project.ext.jetnull_version = '23.0.0'
project.ext.jsr250_version = '1.0'
project.ext.jsr305_version = '3.0.2'
project.ext.trove4j_version = '3.0.3'
// Which native platforms are supported can be specified in the command line. Otherwise
// the default is to support all of them
if (project.hasProperty("native_arch")) {
project.ext.native_arch = [project.native_arch]
} else {
project.ext.native_arch = ["linux-x86_64", "macosx-x86_64", "windows-x86_64"]
}
subprojects {
// Abort if this is Android. It requires a different plugins
if (project.name.contains("android"))
return
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'com.diffplug.spotless'
java {
withJavadocJar()
withSourcesJar()
toolchain { languageVersion = JavaLanguageVersion.of(17) }
}
// Prevents tons of errors if someone is using ASCII
tasks.withType(JavaCompile).configureEach { options.encoding = "UTF-8" }
// Creates Java 11 byte code but Java 17 syntax
tasks.withType(JavaCompile).configureEach {
sourceCompatibility = 17
options.release = 11
}
// Enable incremental compile. Should make single file changes faster
tasks.withType(JavaCompile) { options.incremental = true }
// For some reason examplesJar has a duplicate of ffmpeg pom
tasks.withType(Jar) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }
// To make ErrorProne and Kotlin plugins happy
configurations.configureEach {
resolutionStrategy {
force "org.jetbrains:annotations:$project.jetnull_version"
force "com.google.guava:guava:$project.guava_version"
force "com.google.errorprone:error_prone_annotations:$project.errorprone_version"
force "com.google.code.findbugs:jsr305:$project.jsr305_version"
force 'org.checkerframework:checker-qual:2.10.0'
}
}
// Fail on jar conflict
configurations.configureEach { resolutionStrategy { failOnVersionConflict() } }
repositories {
mavenCentral()
mavenLocal()
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url = 'https://jitpack.io' } // Allows annotations past Java 8 to be used
}
test {
useJUnitPlatform()
reports.html.enabled = false
// Make the error logging verbose to make debugging on CI easier
testLogging.showStandardStreams = true
testLogging.exceptionFormat TestExceptionFormat.FULL
testLogging.showCauses true
testLogging.showExceptions true
testLogging.showStackTraces true
}
sourceSets {
// no auto generated code is allowed in this sourceSet. This is to get around cyclical dependencies
// See docs/AutoGeneratedCode.md
noauto { java { srcDir 'src/noauto/java' } }
// Ensures the code in noauto is also published
main { output.dir(noauto.output) }
benchmark {
java { srcDir 'src/benchmark/java' }
resources { srcDir 'src/benchmark/resources' }
}
generate {
java { srcDir 'src/generate/java' }
resources { srcDir 'src/generate/resources' }
}
experimental {
java { srcDir 'src/experimental/java' }
resources { srcDir 'src/experimental/resources' }
}
}
dependencies {
api("org.georegression:georegression:0.27.3") { exclude group: 'org.ddogleg' }
api("org.ddogleg:ddogleg:0.23.5-SNAPSHOT")
api("net.sf.trove4j:trove4j:${project.trove4j_version}")
compileOnly "org.projectlombok:lombok:${project.lombok_version}"
compileOnly "org.jetbrains:annotations:$project.jetnull_version" // @Nullable
compileOnly "javax.annotation:jsr250-api:$project.jsr250_version" // @Generated
noautoCompileOnly "org.projectlombok:lombok:${project.lombok_version}"
noautoCompileOnly "org.jetbrains:annotations:$project.jetnull_version" // @Nullable
compileOnly "javax.annotation:jsr250-api:$project.jsr250_version" // @Generated
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit_version")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit_version")
experimentalImplementation project.sourceSets.main.compileClasspath
experimentalImplementation project.sourceSets.main.runtimeClasspath
testImplementation project.sourceSets.benchmark.output
testImplementation project.sourceSets.benchmark.compileClasspath
testImplementation project.sourceSets.benchmark.runtimeClasspath
benchmarkImplementation project.sourceSets.experimental.output
benchmarkImplementation project.sourceSets.generate.output
benchmarkImplementation project.sourceSets.main.runtimeClasspath
benchmarkImplementation project.sourceSets.main.compileClasspath
benchmarkImplementation("org.openjdk.jmh:jmh-core:$jmh_version")
benchmarkAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:$jmh_version")
// needed to use Java 11+ syntax with Java 1.8 byte code
annotationProcessor("com.pkware.jabel:jabel-javac-plugin:${project.jabel_version}")
noautoAnnotationProcessor("com.pkware.jabel:jabel-javac-plugin:${project.jabel_version}")
testAnnotationProcessor("com.pkware.jabel:jabel-javac-plugin:${project.jabel_version}")
benchmarkAnnotationProcessor("com.pkware.jabel:jabel-javac-plugin:${project.jabel_version}")
generateAnnotationProcessor("com.pkware.jabel:jabel-javac-plugin:${project.jabel_version}")
annotationProcessor "org.projectlombok:lombok:${project.lombok_version}" // @Getter @Setter
noautoAnnotationProcessor "org.projectlombok:lombok:${project.lombok_version}" // @Getter @Setter
errorprone("com.google.errorprone:error_prone_core:$project.errorprone_version")
// even if it's not used you still need to include the dependency
annotationProcessor "com.uber.nullaway:nullaway:${project.nullaway_version}"
noautoAnnotationProcessor "com.uber.nullaway:nullaway:${project.nullaway_version}"
testAnnotationProcessor "com.uber.nullaway:nullaway:${project.nullaway_version}"
benchmarkAnnotationProcessor "com.uber.nullaway:nullaway:${project.nullaway_version}"
generateAnnotationProcessor "com.uber.nullaway:nullaway:${project.nullaway_version}"
}
tasks.withType(JavaCompile).configureEach {
// Disable ErrorProne for benchmarks and auto code generators and specific third party code
if (project.getName().contains("ffmpeg") || name.startsWith("compileBenchmark") ||
name.startsWith("compileGenerate") || name.startsWith("compileTest") ||
name.startsWith("compileExperimental")) {
options.errorprone.enabled = false
return
}
options.errorprone.enabled = true
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.disable("TypeParameterUnusedInFormals", "StringSplitter", "InconsistentCapitalization",
"HidingField", // this is sometimes done when the specific type is known by child. Clean up later.
"ClassNewInstance", // yes it's deprecated, but new version is more verbose with ignored errors
"FloatingPointLiteralPrecision", // too many false positives in test code
"EmptyCatch", // doesn't acknowledge "ignore". can't get the fix working. Should be an error
"ReferenceEquality", // This is done intentionally a TON. Good test but not here
"MutablePublicArray", // Done intentionally in every case
"CatchAndPrintStackTrace", // Should clean up, but done too often right now
"SameNameButDifferent", // Lombok confuses it
"UnescapedEntity",
"NarrowCalculation", // too many false positives where integer math is done intentionally
"EmptyBlockTag", // E.g. "@param name" is not defined. This should be cleaned up
"AlreadyChecked", // This inspection appears to be broken/too simplistic. False positives galore
)
options.errorprone.error("MissingOverride", "MissingCasesInEnumSwitch", "BadInstanceof",
"NarrowingCompoundAssignment", "JdkObsolete", "MissingSummary")
// Allow sloppy code where it's not published
if (!(name.endsWith("compileJava") || name.endsWith("compileNoautoJava"))) {
options.errorprone.disable("MissingSummary")
}
if (name.startsWith("compileTest")) {
options.errorprone.disable("IntLongMath", "ClassCanBeStatic", "UnnecessaryParentheses")
}
if (name.startsWith("compileBenchmark")) {
options.errorprone.disable("StaticAssignmentInConstructor", "UnusedVariable")
}
options.errorprone {
check("NullAway", CheckSeverity.ERROR)
option("NullAway:TreatGeneratedAsUnannotated", true)
option("NullAway:AnnotatedPackages", "boofcv")
}
}
javadoc {
configure(options) {
links = ['https://docs.oracle.com/en/java/javase/11/docs/api/',
'https://ejml.org/javadoc/',
'https://ddogleg.org/javadoc/',
'https://georegression.org/javadoc/']
failOnError = false
enabled = !project.version.contains("SNAPSHOT") // disable to stop it from spamming stdout
}
// https://github.com/gradle/gradle/issues/11182 Error introduced in JDK 11
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
options.addStringOption("-release", "11")
}
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
failOnError false
}
// Force the release build to fail if it depends on a SNAPSHOT
project.jar.dependsOn project.checkDependsOnSNAPSHOT
// Force publish to fail if trying to upload a stable release and git is dirty
project.publish.dependsOn failDirtyNotSnapshot
// Skip these codeless directories when publishing jars locally or to a remote destination
if (['main', 'integration', 'checks'].contains(name)) {
project.jar.enabled = false
project.tasks.publish.enabled = false
}
if (['autocode'].contains(name)) {
project.tasks.publish.enabled = false
}
spotless {
ratchetFrom 'origin/SNAPSHOT'
format 'misc', {
// define the files to apply `misc` to
target '*.gradle', '*.md', '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
}
java {
// There is currently no good way to exclude files that contain "@Generated" or are not versions.
// This should catch most of them with a few false positives.
target('**/java/boofcv/**/*.java')
targetExclude('**/*_MT*.java', '**/*_F32.java', '**/generated/*')
toggleOffOn('formatter:off', 'formatter:on')
removeUnusedImports()
endWithNewline()
licenseHeaderFile "${project.rootDir}/misc/copyright.txt"
}
}
if (!project.tasks.publish.enabled)
return
// if Maven central isn't setup in ~/.gradle/gradle.properties fill in these variables to make it happy
if (!project.hasProperty('ossrhUsername')) {
ext.ossrhUsername = "dummy"
ext.ossrhPassword = "dummy"
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'BoofCV'
description = 'BoofCV is an open source Java library for real-time computer vision and robotics applications.'
url = 'https://boofcv.org'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'pabeles'
name = 'Peter Abeles'
email = 'peter.abeles@gmail.com'
}
}
scm {
connection = 'scm:git:git://github.com/lessthanoptimal/BoofCV.git'
developerConnection = 'scm:git:git://github.com/lessthanoptimal/BoofCV.git'
url = 'https://github.com/lessthanoptimal/BoofCV'
}
}
}
}
repositories {
maven {
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username ossrhUsername
password ossrhPassword
}
}
}
}
if (ext.ossrhPassword != "dummy") {
signing { sign publishing.publications.mavenJava }
}
}
// Can't reference sourceSets as a dependency until that sub-project has been created which is why this code
// to handle dependencies for auto generated code is defined below. `generate` depends on `noauto` source set
// as a way to avoid a cyclical dependency
//
// See docs/AutoGeneratedCode.md
subprojects {
// Abort if this is Android. It requires a different plugins
if (project.name.contains("android"))
return
project.dependencies {
generateImplementation project(':main:autocode')
generateImplementation project(':main:boofcv-types').sourceSets.noauto.output
}
if (project.path.contains('boofcv-types'))
return
project.dependencies {
// needed for testing Config*
implementation project(':main:boofcv-types').sourceSets.noauto.output
testImplementation project(':main:boofcv-types').sourceSets.test.output
}
}
// list of projects for creating javadoc and jars
def mainProjects = [
':main:boofcv-feature',
':main:boofcv-geo',
':main:boofcv-io',
':main:boofcv-types',
':main:boofcv-ip',
':main:boofcv-ip-multiview',
':main:boofcv-learning',
':main:boofcv-recognition',
':main:boofcv-reconstruction',
':main:boofcv-sfm',
':main:boofcv-simulation',
':integration:boofcv-swing'
]
def integrationProjects = [
':integration:boofcv-ffmpeg',
':integration:boofcv-javacv',
':integration:boofcv-jcodec',
':integration:boofcv-pdf',
':integration:boofcv-WebcamCapture',
]
// Exclude Android because it doesn't generate a jar it creates an aar which is problematic for the script below
def libraryProjects = mainProjects + integrationProjects
def javadocProjects = mainProjects + integrationProjects
checkProjectExistsAddToList(':integration:boofcv-javafx', javadocProjects)
checkProjectExistsAddToList(':integration:boofcv-android', javadocProjects)
// Creates a directory with all the compiled BoofCV jars and the dependencies for main
task createLibraryDirectory(dependsOn: libraryProjects.collect { [it + ':jar', it + ':sourcesJar'] }.flatten()) {
doLast {
// Collects BoofCV jars and external jars
ext.listJars = files(libraryProjects.collect { project(it).configurations.runtimeClasspath })
ext.listJars = ext.listJars.findAll({ !it.isDirectory() }) // remove .class files
ext.fileName = "boofcv-v" + version + "-libs"
file(ext.fileName).deleteDir()
file(ext.fileName).mkdir()
copy {
from ext.listJars
into ext.fileName
}
println("\n\nSaved to directory " + ext.fileName)
}
}
// Creates a single jar which contains all the subprojects in main and integration
task oneJarBin(type: Jar, dependsOn: javadocProjects.collect { it + ":compileJava" }) {
archiveFile.set(file("boofcv-v${project.version}.jar"))
from files(javadocProjects.collect { project(it).sourceSets.main.output }) {
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}
}
// The android code causes javadoc generation to silently fail so we are removing it.
// Someone should investigate this and see if it can be fixed.
def javadocProjectsNoAndroid = javadocProjects.findAll({ !it.contains("android") })
// Generates a global javadoc from all the modules
task alljavadoc(type: Javadoc, group: "Documentation", dependsOn: javadocProjectsNoAndroid.collect { it + ":compileJava" }) {
// only include source code in src directory to avoid including 3rd party code which some projects do as a hack
source = javadocProjectsNoAndroid.collect { project(it).sourceSets.main.allJava } +
javadocProjectsNoAndroid.collect { project(it).sourceSets.noauto.allJava }
classpath = files(javadocProjectsNoAndroid.collect { project(it).sourceSets.main.compileClasspath }) +
files(javadocProjectsNoAndroid.collect { project(it).sourceSets.noauto.compileClasspath })
destinationDir = file("docs/api")
// Hack for Java 8u121 and beyond. Comment out if running an earlier version of Java
options.addBooleanOption("-allow-script-in-comments", true)
// Flag is no longer around in later versions of Java but required before
if (JavaVersion.current().ordinal() < JavaVersion.VERSION_13.ordinal()) {
options.addBooleanOption("-no-module-directories", true)
}
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
// Add a list of uses of a class to javadoc
options.use = true
configure(options) {
failOnError = false
title = "BoofCV ($project.version)"
links = ['https://docs.oracle.com/en/java/javase/11/docs/api',
'https://ejml.org/javadoc/',
'https://georegression.org/javadoc/',
'https://ddogleg.org/javadoc/']
}
// Work around a Gradle design flaw. It won't copy over files in doc-files
doLast {
copy {
from javadocProjects.collect { project(it).fileTree('src/main/java').include('**/doc-files/*') }
into destinationDir
}
}
}
task alljavadocWeb() {
doFirst {
alljavadoc.options.bottom = file('misc/bottom.txt').text
alljavadoc.destinationDir = file("docs/api-web")
}
}
alljavadocWeb.finalizedBy(alljavadoc)
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Android project has a different testing system so skip it
reportOn subprojects.findAll {!it.name.contains("android")}.test
}
// Sanity check to make sure that autogenerate has been called. This is the source of a lot of confusion from users
project(":main:boofcv-types") {
// This is the first task that the main source code will depend on
tasks.findByName("compileJava").doFirst { task ->
// Determine the sourceSet by looking at the path
def iterator = task.stableSources.iterator()
if (!iterator.hasNext())
return
// Get the path to the first file and compensate for how file paths are specified on Windows
def path = iterator.next().path.replace("\\", "/")
// make sure it's only checking the main source set
if (!path.contains("boofcv-types/src/main"))
return
// See if an arbitrary auto generated file exists
if (file("src/main/java/boofcv/struct/border/ImageBorder_F32.java").exists())
return
// Attempt to make this error very obvious despite all the "helpful" text gradle dumps afterwards
throw new InvalidUserDataException("*****\n You must run './gradlew autogenerate' before you can build!\n*****")
}
}
wrapper {
distributionType = Wrapper.DistributionType.BIN
gradleVersion = '7.6.4'
}