forked from qupath/qupath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
682 lines (574 loc) · 19.6 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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/**
* Gradle script for building QuPath.
* <p>
* To create a complete build including associated license files, try the following:
* <p>
* ./gradlew clean build createPackage -Ppackager=/full/path/to/jpackage
* or on Windows
* gradlew.bat clean build createPackage -Ppackager=/full/path/to/jpackage.exe
*/
/**
* Configure build script
*/
buildscript {
dependencies {
classpath 'com.github.jk1:gradle-license-report:1.11'
// classpath 'org.anarres.jarjar:jarjar-gradle:1.0.1'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'https://plugins.gradle.org/m2/' }
}
}
/*
* Using java-library rather than java enables us to define api dependencies,
* i.e. dependencies exported from the API of QuPath.
* An example if JTS, since QuPath ROIs can be converted to JTS Geometries and this
* should be accessible throughout the software.
*/
plugins {
id 'java-library'
}
/*
* Some metadata for the manifest
*/
def qupathVersion = file('VERSION').text.trim()
def qupathVendor = "QuPath developers"
println 'Building QuPath version ' + qupathVersion
/*
* Output location; once things are gathered here, they can be used as input for jpackager
*/
def qupathOutputDir = 'qupath'
def additionalResourcesDir = "build/${qupathOutputDir}"
/*
* JavaFX version
*/
def jfxVersion = '13.0.1'
/*
* Include OpenCV binaries with GPU support (quite big, may not be used?)
*/
def useGPU = false
/*
* Modules not yet supported (because of some dependency troubles).
* This disables code that would otherwise try to move in a modular direction.
*/
def doModular = false
/*
* Helps to output build time for reference later
*/
def buildTime = new Date().format("yyyy-MM-dd, HH:mm")
/*
* Good to know what JDK is (sometimes accidentally) being used
*/
println 'Current Java version: ' + JavaVersion.current()
println System.properties['java.home']
// Request latest commit by a command line call to Git, if required
def requestLatestCommit = project.findProperty('request-git-tag') == 'true'
// Including the latest commit when building can help traceability - but requires git being available
ext {
latestGitCommit = null
}
if (requestLatestCommit) {
try {
def stdout = new ByteArrayOutputStream()
def result = exec {
commandLine 'git', 'log', "--pretty=format:'%h'", "-n 1"
standardOutput = stdout
}
latestGitCommit = stdout.toString().trim()
println 'Latest commit: ' + latestGitCommit
} catch (Exception e) {
println 'Unable to get latest commit: ' + e.getLocalizedMessage()
latestGitCommit = 'Unknown (is Git installed?)'
}
} else {
println "I won't try to get the last commit - consider running with '-Prequest-git-tag=true' if you want this next time (assuming Git is installed)"
}
/*
* Handle OS-specific decisions
*/
import org.gradle.internal.os.OperatingSystem
println 'Operating system: ' + OperatingSystem.current()
def nativesCPP
def platform
def nativesClassifier
String iconName
if (OperatingSystem.current().isMacOsX()) {
nativesClassifier = 'natives-osx'
nativesCPP = 'macosx-x86_64'
platform = 'mac'
iconName = 'macosx/qupath.icns'
} else if (OperatingSystem.current().isLinux()) {
nativesClassifier = 'natives-linux'
nativesCPP = 'linux-x86_64'
platform = 'linux'
iconName = 'linux/QuPath.png'
} else if (OperatingSystem.current().isWindows()) {
nativesClassifier = 'natives-windows'
if (System.properties['sun.arch.data.model'] == '32') {
println "WARNING: You appear to be using a 32-bit JDK - If I can't find a 32-bit version of JavaFX, this will fail! Probably at the 'test' stage."
nativesCPP = 'windows-x86'
} else
nativesCPP = 'windows-x86_64'
platform = 'win'
iconName = 'windows/QuPath.ico'
} else {
println 'Unknown operating system!'
}
/*
* Note on OpenCV, OpenBLAS & Mac.
* This appears to segfault sometimes, in which case the following command line parameters may help:
* -Dorg.bytedeco.openblas.load=blas -Djava.library.path=.:/usr/lib/
* See https://github.com/bytedeco/javacpp-presets/tree/master/openblas for further information.
*
* Another way to avoid requiring this is to set the number of threads to 1 within the QuPath code.
*/
/*
* Easier to use the wrapper with source
*/
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
/*
* jarjar makes it possible to remove the troublesome MacAdapter in ij.jar,
* which doesn't work for JDK 9+ and causes module issue because it is not contained
* within any package.
*
* Only required if building modules. Currently all instances commented out.
*/
//apply plugin: 'org.anarres.jarjar'
/*
* Define managed dependencies for use within sub-projects
*/
allprojects {
group = 'qupath'
version = qupathVersion
ext {
bioformatsVersion = '6.3.0'
commonsMathVersion = '3.6.1'
controlsfxVersion = '11.0.0'
groovyVersion = '2.5.8'
gsonVersion = '2.8.6'
guavaVersion = '28.1-jre'
imagejVersion = '1.52r'
jfxtrasVersion = '10.0-r1'
jpenVersion = '2-150301'
jtsVersion = '1.16.1'
openslideVersion = '3.4.1_2'
richtextVersion = '0.10.2'
// Note, if OpenCV is a SNAPSHOT version then it must already be installed locally (with Maven)
opencvVersion = '4.1.2-1.5.2'
}
configurations {
jts
groovy
richtextfx
commonsmath
gson
controlsfx
jfxtras
opencv
jpen
imagej
openslide
javafx
nativeloader
guava
picocli
// Guava tries to bring in extra dependencies not required at runtime
implementation {
exclude group: 'com.google.code.findbugs'
exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations'
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
exclude group: 'com.google.j2objc', module: 'j2objc-annotations'
exclude group: 'org.checkerframework', module: 'checker-qual'
}
}
dependencies {
jts "org.locationtech.jts:jts-core:${jtsVersion}"
// Optionally add GeoJSON support (brings in json-simple as sub-dependency)
// However, the use of simple-json is troublesome since it brings in an old version of junit
// jts "org.locationtech.jts.io:jts-io-common:${jtsVersion}"
groovy "org.codehaus.groovy:groovy:${groovyVersion}"
groovy "org.codehaus.groovy:groovy-jsr223:${groovyVersion}"
for (fx in ['javafx-base', 'javafx-controls', 'javafx-graphics', 'javafx-media', 'javafx-web', 'javafx-swing']) {
javafx "org.openjfx:${fx}:${jfxVersion}"
javafx "org.openjfx:${fx}:${jfxVersion}:${platform}"
}
richtextfx "org.fxmisc.richtext:richtextfx:${richtextVersion}"
commonsmath "org.apache.commons:commons-math3:${commonsMathVersion}"
gson "com.google.code.gson:gson:${gsonVersion}"
controlsfx "org.controlsfx:controlsfx:${controlsfxVersion}"
jfxtras "org.jfxtras:jfxtras-menu:${jfxtrasVersion}"
opencv "org.bytedeco:opencv:${opencvVersion}"
if (nativesCPP != null) {
opencv "org.bytedeco:openblas::${nativesCPP}" // Required for OpenCV with JavaCPP >= 1.5.1
if (useGPU)
opencv "org.bytedeco:opencv:${opencvVersion}:${nativesCPP}-gpu"
else
opencv "org.bytedeco:opencv:${opencvVersion}:${nativesCPP}"
}
jpen "net.sourceforge.jpen:jpen:${jpenVersion}"
if (nativesClassifier != null)
jpen "net.sourceforge.jpen:jpen:${jpenVersion}:${nativesClassifier}"
imagej "net.imagej:ij:${imagejVersion}"
// imagej jarjar.repackage {
// from "net.imagej:ij:${imagejVersion}"
// classDelete 'MacAdapter'
// }
openslide "org.openslide:openslide:${openslideVersion}"
if (nativesClassifier != null)
openslide "org.openslide:openslide:${openslideVersion}:${nativesClassifier}"
guava "com.google.guava:guava:${guavaVersion}"
}
}
/*
* Define inter-dependencies of sub-projects
*/
project(':qupath-core-processing') {
dependencies {
implementation project(':qupath-core')
}
}
project(':qupath-gui-fx') {
dependencies {
implementation project(':qupath-core'), project(':qupath-core-processing')
}
}
/*
* All extensions require the GUI module
*/
configure( subprojects.findAll {it.name.contains('-extension') || it.name.contains('-experimental')} ) {
dependencies {
implementation project(':qupath-core'), project(':qupath-core-processing'), project(':qupath-gui-fx')
}
}
/*
* Not everybody is ready to be a module yet...
*/
def moduleExclusionFilter = {String moduleName -> !doModular || moduleName.contains('bioformats') || moduleName.contains('jpen')}
subprojects {
afterEvaluate {
compileJava {
if (moduleExclusionFilter(moduleName))
return
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
jar {
// Important to set version so this can be queried within QuPath
inputs.property("moduleName", moduleName)
manifest {
def manifestAttributes = [
"Implementation-Vendor": qupathVendor,
"Implementation-Version": qupathVersion,
'Automatic-Module-Name': moduleName,
"QuPath-build-time": buildTime
]
if (latestGitCommit != null)
manifestAttributes["QuPath-latest-commit"] = latestGitCommit
attributes(manifestAttributes)
}
}
compileTestJava {
if (moduleExclusionFilter(moduleName))
return
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'junit',
'--add-reads', "$moduleName=junit",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
]
classpath = files()
}
}
test {
if (moduleExclusionFilter(moduleName))
return
inputs.property("moduleName", moduleName)
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'ALL-MODULE-PATH',
'--add-reads', "$moduleName=junit",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath,
]
classpath = files()
}
}
}
}
/*
* Build all projects
*/
allprojects {
apply plugin: 'java-library'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenLocal()
mavenCentral()
maven {
name 'Unidata'
url 'https://artifacts.unidata.ucar.edu/content/repositories/unidata-releases'
}
maven {
url 'https://artifacts.openmicroscopy.org/artifactory/maven/'
}
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
maven { url "../maven/repo" }
}
// May use this in the future, but fails where javadocs are incomplete
// java {
// withJavadocJar()
// }
dependencies {
implementation group: 'ch.qos.logback', name: 'logback-classic', version:'1.2.3'
testImplementation group: 'junit', name: 'junit', version:'4.12'
}
}
/*
* Build the main launcher class
*/
apply plugin: 'java-library'
rootProject.libsDirName = qupathOutputDir
repositories {
mavenLocal()
mavenCentral()
maven { url "./maven/repo" }
}
/*
* I suspect there may be a cleaner way to specify subprojects...
*/
dependencies {
implementation "org.openjfx:javafx-graphics:${jfxVersion}"
implementation "org.openjfx:javafx-graphics:${jfxVersion}:${platform}"
subprojects {
implementation it
}
}
/*
* Copy licenses from subprojects to include in distribution
*/
task copyLicenses(type: Copy) {
def licenseDirs = []
subprojects.each {
def dir = new File(it.projectDir, 'src/main/resources/licenses')
if (dir.isDirectory())
licenseDirs << dir
}
println 'Copying license directories: '
licenseDirs.each { println ' ' + it }
from licenseDirs
into additionalResourcesDir + '/licenses'
}
/*
* Get the main changelog & license
*/
task copyChangelog(type: Copy) {
from project.rootDir
into additionalResourcesDir
include 'CHANGELOG.md'
include 'STARTUP.md'
include 'LICENSE.txt'
include 'VERSION'
}
/*
* Extract native libraries where necessary
*/
task extractNativeLibraries() {
if (nativesClassifier == null)
return
configurations.runtimeClasspath.files.findAll({ it.getName().contains(nativesClassifier) }).each { file ->
println 'Extracting native libraries from ' + file + " into " + additionalResourcesDir
doLast {
copy {
from zipTree(file)
into additionalResourcesDir
exclude "/META-INF/"
}
}
}
}
/*
* Copy required jars all into one directory
*/
task copyRuntimeLibs(type: Copy) {
into additionalResourcesDir
from configurations.runtimeClasspath
}
/*
* Run automated license generation (in addition to manually-curated licenses)
*/
apply plugin: 'com.github.jk1.dependency-license-report'
import com.github.jk1.license.render.*
import com.github.jk1.license.filter.*
import java.nio.file.Paths
licenseReport {
print("LICENSE PATH: " + new File(projectDir, 'license-unknown.txt').getAbsolutePath())
filters = [new LicenseBundleNormalizer()]
renderers = [new TextReportRenderer('THIRD-PARTY.txt'),
new CsvReportRenderer(),
new InventoryHtmlReportRenderer('index.html', 'Third party licenses',
new File(projectDir, 'license-unknown.txt'))]
}
task copyLicenseReport(type: Copy) {
from 'build/reports/dependency-license/THIRD-PARTY.txt'
into additionalResourcesDir + '/licenses'
}
/*
* Specify the order of some operations
*/
copyLicenses.dependsOn generateLicenseReport
copyLicenseReport.dependsOn generateLicenseReport
jar.dependsOn copyLicenses
jar.dependsOn copyChangelog
jar.dependsOn extractNativeLibraries
build.dependsOn copyLicenseReport
build.dependsOn copyRuntimeLibs
/*
* Squeeze some useful metadata into the Manifest of the main jar -
* QuPath can display this through the GUI
*/
jar {
manifest {
def manifestAttributes = [
"Implementation-Vendor": qupathVendor,
"Implementation-Title": 'QuPath',
"Implementation-Version": qupathVersion,
"Main-Class": "qupath.QuPath",
"Class-Path": configurations.compileClasspath.collect { it.getName() }.join(' '),
"QuPath-build-time": buildTime
]
if (latestGitCommit != null)
manifestAttributes["QuPath-latest-commit"] = latestGitCommit
attributes(manifestAttributes)
}
}
/*
* Create javadocs for all modules/packages in one place.
*/
task mergedJavadocs(type: Javadoc) {
source subprojects.collect { project ->
project.sourceSets.main.allJava
}
destinationDir = new File(buildDir, 'merged-docs')
classpath = files(subprojects.collect { project ->
project.sourceSets.main.compileClasspath
})
}
/*
* Create a custom runtime. Mostly to avoid using the same one as jpackager for now.
*/
task createRuntime(dependsOn:build, type:Exec) {
def outputDir = new File(rootProject.buildDir, 'jre')
// Reuse existing JRE if available
onlyIf { !outputDir.exists() }
doFirst {
def params = ["${System.properties['java.home']}/bin/jlink"]
params << '--output' << outputDir.getAbsolutePath()
params << '--add-modules' << 'java.desktop,java.xml,java.scripting,java.sql,java.naming,jdk.unsupported,jdk.zipfs'
params << '--strip-debug'
params << '--no-header-files'
params << '--no-man-pages'
params << '--strip-native-commands'
params << '--compress=2'
// params << '--module-path' << System.properties.'java.home' + '/jmods'
print String.join(' ', params)
commandLine = params
}
}
/*
* If we have a packager (somewhere), use it.
*
* To call this:
* gradlew createPackage -Ppackager=/path/to/jpackager
*
* Or to make an installer:
* gradlew createPackage -Ppackager=/path/to/jpackager -Ptype=installer}
*/
task createPackage(dependsOn:createRuntime, type:Exec) {
doFirst {
def packager = findProperty('packager')
if (packager == null || !new File(packager).exists()) {
println '-------'
println 'Please specify where I can find a suitable packager! Something like this:'
if (OperatingSystem.current().isWindows())
println 'gradlew.bat createPackage -Ppackager=/full/path/to/jpackage.exe'
else
println 'gradlew createPackage -Ppackager=/full/path/to/jpackage'
println 'Current value of -Ppackager is ' + packager
println 'Note: You can also specify this in a gradle.properties file'
println '-------'
throw new GradleException('Please specify where I can find a suitable jpackage!')
}
println 'Using packager: ' + packager
// Versioning rules can be strict on some platforms - may need to further change this
def appVersion = qupathVersion.replace('-SNAPSHOT', '')
def packageType = findProperty('type')
def params = [packager]
params << '--input' << new File(rootProject.buildDir, rootProject.libsDirName).getAbsolutePath()
params << '--dest' << new File(rootProject.buildDir, 'dist').getAbsolutePath()
params << '--main-jar' << jar.archiveName
params << '--name' << 'QuPath-' + qupathVersion
// params << '--class' << 'qupath.QuPath'
// Default to using 50% available memory
params << '--java-options' << '-XX:MaxRAMPercentage=50'
if (OperatingSystem.current().isMacOsX()) {
params << '--mac-package-name' << 'QuPath'
params << '--mac-package-identifier' << 'QuPath'
if (packageType == 'installer') {
params << '--type' << 'dmg'
} else {
params << '--type' << 'app-image'
}
} else if (OperatingSystem.current().isWindows()) {
if (packageType == 'installer') {
params << '--type' << 'msi'
params << '--win-menu'
params << '--win-menu-group' << 'QuPath'
params << '--win-dir-chooser'
params << '--win-shortcut'
params << '--win-per-user-install'
int lastDash = appVersion.lastIndexOf('-')
if (lastDash > 0) {
appVersion = appVersion.substring(0, lastDash)
println "Simplifying QuPath version ${qupathVersion} to ${appVersion} for compatibility"
}
} else
params << '--type' << 'app-image'
// Create a separate launcher with a console - this can help with debugging
def fileTemp = File.createTempFile('qupath-building', '.properties')
def consoleLauncherName = "QuPath-${qupathVersion} (debug)"
fileTemp.deleteOnExit()
fileTemp.text = 'win-console=true'
// fileTemp << System.lineSeparator() << 'java-options=' << '"-Dqupath.config="' << consoleLauncherName + '.cfg""'
params << '--add-launcher' << "\"${consoleLauncherName}\"=\"${fileTemp.getAbsolutePath()}\""
} else
params << '--type' << 'app-image'
// Store the app version (typically a simplified version of the full format)
params << '--app-version' << appVersion
// Try to find the icon
def pathIcon = Paths.get(
rootProject.buildDir.getAbsolutePath(),
'resources', 'main', 'package',
iconName).toFile().getAbsolutePath()
params << '--icon' << pathIcon
params << '--runtime-image' << new File(rootProject.buildDir, 'jre').getAbsolutePath()
// params << '--add-modules' << 'java.desktop,java.xml,java.scripting,java.sql,java.naming,jdk.unsupported'
// params << '--module-path' << System.properties.'java.home' + '/jmods'
println String.join(' ', params)
commandLine = params
}
}