forked from qupath/qupath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
846 lines (700 loc) · 24.4 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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
/**
* Gradle script for building QuPath.
* <p>
* To create a complete build including associated license files, try the following:
* <p>
* ./gradlew clean build createPackage
* or on Windows
* gradlew.bat clean build createPackage
*/
/**
* Configure build script
*/
buildscript {
dependencies {
classpath 'com.github.jk1:gradle-license-report:1.14'
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 is JTS, since QuPath ROIs can be converted to JTS Geometries and this
* should be accessible throughout the software.
*/
plugins {
id 'java-library'
id 'org.javamodularity.moduleplugin' version '1.6.0' apply false
}
/*
* 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 jpackage
*/
def qupathOutputDir = 'qupath'
def additionalResourcesDir = "build/${qupathOutputDir}"
/*
* JavaFX version
*/
def jfxVersion = '14.0.1'
/*
* Placeholder to use OpenCV binaries with GPU support... if/when this is supported (warning: they are quite big)
*/
def useGPU = false
/*
* Modules not yet supported because of various dependency troubles.
* Specifially:
* - ImageJ contains MacAdapter outside of any package, this must be removed
* (jarjar-gradle can do the job, but it seems to confuse eclipse)
* - RuntimeTypeAdapterFactory needs to be in a valid package
* - JPen's automatic module name is invalid (jpen.2)
* - Bio-Formats is not module-friendly
* - OpenSlide also seems module-unfriendly (at least within eclipse)
* Setting the flag to false disables code that would otherwise try to move in a modular direction,
* while making it a bit easier to return to this later.
*/
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) {
logger.warn('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') {
logger.warn("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 {
logger.warn('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.
*/
if (doModular) {
apply plugin: 'org.anarres.jarjar'
}
/*
* Check command arguments to optional inclusions/exclusions
*/
def includeTensorFlowGPU = (findProperty('tensorflow-gpu') ?: "false") != "false"
def includeTensorFlow = includeTensorFlowGPU || (findProperty('tensorflow-cpu') ?: "false") != "false"
def excludeSubprojects = []
if (includeTensorFlowGPU) {
println 'Requesting TensorFlow (GPU) subproject'
} else if (includeTensorFlow) {
println 'Requesting TensorFlow (CPU) subproject'
} else {
excludeSubprojects << 'qupath-extension-tensorflow'
println "Use -Ptensorflow-cpu=true or -Ptensorflow-gpu=true if you wish to include experimental TensorFlow module"
}
/*
* Define managed dependencies for use within sub-projects
*/
allprojects {
apply plugin: 'java-library'
if (doModular) {
apply plugin: 'org.javamodularity.moduleplugin'
}
group = 'qupath'
version = qupathVersion
ext {
// Java compatibility version
javaVersion = 11
// Dependency versions
bioformatsVersion = '6.5.0'
commonsMathVersion = '3.6.1'
commonsTextVersion = '1.8'
controlsfxVersion = '11.0.1'
groovyVersion = '3.0.3'
gsonVersion = '2.8.6'
guavaVersion = '29.0-jre'
imagejVersion = '1.53a'
jfxtrasVersion = '10.0-r1'
jpenVersion = '2-150301'
jtsVersion = '1.16.1'
openslideVersion = '3.4.1_2'
richtextVersion = '0.10.5'
picocliVersion = '4.3.2'
jfreesvgVersion = '4.1'
// Note, if OpenCV is a SNAPSHOT version then it must already be installed locally (with Maven)
javacppVersion = '1.5.3'
opencvVersion = "4.3.0-${javacppVersion}"
// Additional versions
logbackVersion = '1.2.3'
slf4jVersion = '1.3.0'
junitVersion = '5.6.2'
// Optional versions
tensorflowVersion = "1.15.2-${javacppVersion}"
mkldnnVersion = "0.21.4-${javacppVersion}"
/*
* Link to the main external Javadocs if -PlinkJavadoc=true
*/
if (findProperty('linkJavadoc'))
externalJavadocs = [
"https://docs.oracle.com/en/java/javase/11/docs/api/",
// "https://openjfx.io/javadoc/11/", // The fact we don't yet use modules causes trouble here; see https://bugs.openjdk.java.net/browse/JDK-8240169
"https://javadoc.io/doc/org.controlsfx/controlsfx/", // May not be working..?
"https://imagej.nih.gov/ij/developer/api/",
"https://locationtech.github.io/jts/javadoc/",
"https://javadoc.io/doc/com.google.code.gson/gson/latest",
"https://javadoc.io/doc/org.bytedeco/javacpp/" + javacppVersion
]
else
externalJavadocs = []
}
configurations {
jts
groovy
richtextfx
commonsmath
commonstext
gson
controlsfx
jfxtras
opencv
jpen
imagej
bioformats
openslide
javafx
nativeloader
guava
picocli
jfreesvg
junit
logback
// Optional
tensorflow
}
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}"
groovy "org.codehaus.groovy:groovy-xml:${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}"
commonstext "org.apache.commons:commons-text:${commonsTextVersion}"
gson "com.google.code.gson:gson:${gsonVersion}"
controlsfx "org.controlsfx:controlsfx:${controlsfxVersion}", {
// ControlsFX 11.0.1 uses a linux classifier to bring in more JavaFX than it may need
exclude group: 'org.openjfx'
}
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
opencv "org.bytedeco:javacpp:{$javacppVersion}:${nativesCPP}"
}
if (useGPU) {
logger.warn("Requested useGPU... so this will probably fail - please don't do that")
opencv "org.bytedeco:opencv:${opencvVersion}:${nativesCPP}-gpu"
// Isn't terribly clear if this is also needed when requesting GPU?
//opencv "org.bytedeco:opencv:${opencvVersion}:${nativesCPP}"
} else
opencv "org.bytedeco:opencv:${opencvVersion}:${nativesCPP}"
jpen "net.sourceforge.jpen:jpen:${jpenVersion}"
if (nativesClassifier != null)
jpen "net.sourceforge.jpen:jpen:${jpenVersion}:${nativesClassifier}"
if (doModular) {
imagej jarjar.repackage {
from "net.imagej:ij:${imagejVersion}"
classDelete 'MacAdapter'
}
} else
imagej "net.imagej:ij:${imagejVersion}"
bioformats "ome:formats-gpl:${bioformatsVersion}", {
exclude group: 'xalan', module: 'serializer'
exclude group: 'xalan', module: 'xalan'
exclude group: 'io.minio', module: 'minio'
exclude group: 'commons-codec', module: 'commons-codec'
exclude group: 'commons-logging', module: 'commons-logging'
// exclude group: 'edu.ucar', module: 'cdm'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'com.google.code.findbugs', module: 'annotations'
}
openslide "org.openslide:openslide:${openslideVersion}"
if (nativesClassifier != null)
openslide "org.openslide:openslide:${openslideVersion}:${nativesClassifier}"
guava "com.google.guava:guava:${guavaVersion}", {
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'
}
picocli "info.picocli:picocli:${picocliVersion}"
jfreesvg "org.jfree:org.jfree.svg:${jfreesvgVersion}"
junit "org.junit.jupiter:junit-jupiter:${junitVersion}"
// junit "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
logback "ch.qos.logback:logback-classic:${logbackVersion}"
logback "org.slf4j:slf4j-api:${slf4jVersion}"
tensorflow "org.bytedeco:tensorflow:${tensorflowVersion}"
if (includeTensorFlowGPU)
tensorflow "org.bytedeco:tensorflow:${tensorflowVersion}:${nativesCPP}-gpu"
else
tensorflow "org.bytedeco:tensorflow:${tensorflowVersion}:${nativesCPP}"
tensorflow "org.bytedeco:mkl-dnn:${mkldnnVersion}"
tensorflow "org.bytedeco:mkl-dnn:${mkldnnVersion}:${nativesCPP}"
}
javadoc {
def strictJavadoc = findProperty('strictJavadoc')
if (!strictJavadoc) {
options.addBooleanOption 'Xdoclint:none', true
}
options {
links += externalJavadocs
}
def docPath = "${rootProject.buildDir}/docs/${project.name}"
destinationDir = file(docPath)
}
}
/*
* Define inter-dependencies of sub-projects
*/
project(':qupath-core-processing') {
dependencies {
api project(':qupath-core')
}
}
project(':qupath-gui-fx') {
dependencies {
api 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')
}
}
subprojects {
afterEvaluate {
compileJava {
/*
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)
}
}
test {
useJUnitPlatform()
}
}
}
/*
* Build all projects
*/
allprojects {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
repositories {
mavenLocal()
mavenCentral()
// May be required for snapshot ImageJ2 jars
maven { url 'https://maven.imagej.net/content/groups/public' }
// Required for Bio-Formats
maven {
name 'Unidata'
url 'https://artifacts.unidata.ucar.edu/content/repositories/unidata-releases'
}
maven { url 'https://artifacts.openmicroscopy.org/artifactory/maven/' }
// May be required for snapshot JavaCPP jars
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
// Currently required for OpenSlide
maven { url "../maven/repo" }
}
// May use this in the future, but fails where javadocs are incomplete
// java {
// withJavadocJar()
// }
configurations {
implementation.extendsFrom logback
testImplementation.extendsFrom junit
}
}
/*
* Build the main launcher class
*/
apply plugin: 'java-library'
rootProject.libsDirName = qupathOutputDir
repositories {
mavenLocal()
mavenCentral()
maven { url "./maven/repo" }
}
configurations {
implementation.extendsFrom picocli
}
/*
* 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 {
if (!excludeSubprojects.contains(it.name))
implementation it
else
println 'Excluding ' + 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()] // May introduce errors
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.runtimeClasspath.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.
* Use -PstrictJavadoc=true to fail on error with doclint (which is rather strict).
*/
def strictJavadoc = findProperty('strictJavadoc')
task mergedJavadocs(type: Javadoc) {
if (!strictJavadoc) {
options.addBooleanOption 'Xdoclint:none', true
}
source subprojects.collect { project ->
project.sourceSets.main.allJava.filter {it.name != 'module-info.java'}
}
options {
links += rootProject.ext.externalJavadocs
source = javaVersion
}
destinationDir = new File(buildDir, 'merged-docs')
classpath = files(subprojects.collect { project ->
project.sourceSets.main.compileClasspath
})
}
/*
* Create a custom runtime
*/
task createRuntime(dependsOn:build, type:Exec) {
String jreModules = findProperty('jreModules')
if (!jreModules) {
jreModules = 'default'
}
def outputDir = new File(rootProject.buildDir, 'jre')
// Reuse existing JRE if available
onlyIf { !outputDir.exists() }
doFirst {
// Indispensible modules
def requiredModules = [
'java.desktop',
'java.xml',
'java.scripting',
'java.sql',
'java.naming',
'jdk.unsupported',
'jdk.zipfs', // Needed for zip filesystem support
]
def usefulModules = [
'java.net.http', // Add HttpClient support (may be used by scripts)
'java.management', // Useful to check memory usage
'jdk.management.agent' // Enables VisualVM to connect and sample CPU use
]
def addModules
if (jreModules == 'all') {
println 'Creating Java runtime using all modules'
addModules = 'ALL-MODULE-PATH'
} else if (jreModules == 'minimum') {
println 'Creating minimal Java runtime (this may exclude some useful modules)'
addModules = String.join(',', requiredModules)
} else {
if (jreModules != 'default')
logger.warn("Unsupported jreModules property '${jreModules}', will use 'default' instead")
println 'Creating default Java runtime'
addModules = String.join(',', requiredModules + usefulModules)
}
def params = ["${System.properties['java.home']}/bin/jlink"]
params << '--output' << outputDir.getAbsolutePath()
params << '--add-modules' << addModules
if (jreModules == 'default')
params << '--bind-services'
params << '--strip-debug'
params << '--no-header-files'
params << '--no-man-pages'
params << '--strip-native-commands'
params << '--compress=2'
print String.join(' ', params)
commandLine = params
}
}
/*
* Create a native package. This requires jpackage, first included within JDK 14.
*/
task createPackage(dependsOn:createRuntime, type:Exec) {
doFirst {
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_14)) {
throw new GradleException("Creating a package requires jpackage in JDK 14, but the current JDK version is ${JavaVersion.current()}.")
}
// Versioning rules can be strict on some platforms - may need to further change this
def appVersion = qupathVersion.replace('-SNAPSHOT', '')
def packageType = findProperty('type')
if (!packageType) {
packageType = 'app-image'
logger.info("No package type specified, using default ${packageType}")
}
boolean associateFiles = packageType != 'app-image'
def params = ["${System.properties['java.home']}/bin/jpackage"]
params << '--input' << new File(rootProject.buildDir, rootProject.libsDirName).getAbsolutePath()
params << '--dest' << new File(rootProject.buildDir, 'dist').getAbsolutePath()
params << '--main-jar' << jar.archiveName
String launcherName = 'QuPath-' + qupathVersion
params << '--name' << launcherName
// params << '--name' << 'QuPath-' + qupathVersion
// 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' << 'pkg'
} else {
params << '--type' << packageType
}
associateFiles = true // Should work for Mac
} 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)
logger.info("Simplifying QuPath version ${qupathVersion} to ${appVersion} for compatibility")
}
} else
params << '--type' << packageType
// Create a separate launcher with a console - this can help with debugging
def fileTemp = File.createTempFile('qupath-building', '.properties')
def consoleLauncherName = launcherName + " (console)"
fileTemp.deleteOnExit()
fileTemp.text = 'win-console=true'
fileTemp << System.lineSeparator() << 'java-options=' << '-XX:MaxRAMPercentage=50' << ' -Dqupath.config=console'
// fileTemp << System.lineSeparator() << 'java-options=' << '-Dqupath.config=console'
params << '--add-launcher' << "\"${consoleLauncherName}\"=\"${fileTemp.getAbsolutePath()}\""
} else
params << '--type' << packageType
// 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
// Set file associations
if (associateFiles) {
def associations = Paths.get(
rootProject.buildDir.getAbsolutePath(),
'resources', 'main', 'package', 'associations').toFile().listFiles()
associations.each {
if (it.isFile() && it.name.endsWith('.properties'))
params << '--file-associations' << it.getAbsolutePath()
}
}
params << '--runtime-image' << new File(rootProject.buildDir, 'jre').getAbsolutePath()
println String.join(' ', params)
commandLine = params
}
}