-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
406 lines (355 loc) · 15 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
plugins {
id 'java'
id 'idea'
id 'application'
id 'com.github.ben-manes.versions' version '0.51.0'
id 'net.nemerosa.versioning' version '3.1.0'
id 'org.openjfx.javafxplugin' version '0.1.0'
id 'org.gradlex.extra-java-module-info' version '1.8'
id 'org.beryx.jlink' version '3.0.1'
}
ext {
artifactName = 'trinity'
artifactNameUpper = artifactName.capitalize()
buildDate = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone('UTC'))
moduleName = 'edu.jhuapl.trinity'
mainClassPath = 'edu.jhuapl.trinity.App'
mainClassJarLauncher = 'edu.jhuapl.trinity.TrinityMain'
isProdJar = findProperty('env') == 'prod-jar'
isProdJlink = findProperty('env') == 'prod-jlink'
isDevelopment = findProperty('env') == 'dev'
fxVersion = findProperty('javafx.version')
fxStaticVersion = findProperty('javafx.static.version')
}
group = 'trinity'
version = new Date().format('yyyy.MM.dd', TimeZone.getTimeZone('UTC'))
description = 'Trinity provides performance analysis and XAI tools ideal for Deep Learning systems or other models performing complex classification or decoding.'
// Output Build Info at Startup
println "Working Directory: $rootDir"
println "Java Being Used: ${System.getProperty('java.home')}"
println "Building Module: $moduleName/$mainClassPath $version with FX v$fxVersion"
println "Build Start Time: $buildDate"
println "Is Development: $isDevelopment"
println "Executing: ${gradle.startParameter.getTaskNames()}"
println "OS Detected: ${org.gradle.internal.os.OperatingSystem.current()}"
// <editor-fold desp="Project Dependencies">
repositories {
mavenCentral()
}
dependencies {
// Excluding openjfx from 3rd party modules.
implementation(group: 'com.github.birdasaur.litfx', name: 'litfx-controls', version: '0.1.3') {
exclude group: 'org.openjfx'
}
implementation(group: 'org.fxyz3d', name: 'fxyz3d', version: '0.6.0') {
exclude group: 'org.openjfx'
}
implementation(group: 'eu.hansolo.fx', name: 'charts', version: '21.0.19') {
exclude group: 'org.openjfx'
exclude group: 'ch.qos.logback'
}
implementation group: 'com.github.quickhull3d', name: 'quickhull3d', version: '1.0.0'
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.15.0'
implementation group: 'org.zeromq', name: 'jeromq', version: '0.6.0'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.17.2'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.17.2'
implementation group: 'com.github.sarxos', name: 'webcam-capture', version: '0.3.12'
implementation group: 'org.jflac', name: 'jflac-codec', version: '1.5.2'
// Enforce slf4j-api version across dependencies
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.15'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.8'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.3'
testImplementation 'org.junit.platform:junit-platform-suite:1.10.3'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.3'
}
// Make sure every single dependency is modularized.
// Alternative is to use org.javamodularity.moduleplugin but
// it doesn't yield the same quality of results.
extraJavaModuleInfo {
// Avoid automatic modules
failOnAutomaticModules.set(true)
// Transitive of org.fxyz3d:fxyz3d
module('eu.mihosoft.vvecmath:vvecmath', 'vvecmath') {
exports('eu.mihosoft.vvecmath')
}
// Transitive of org.fxyz3d:fxyz3d
module('eu.mihosoft.vrl.jcsg:jcsg', 'jcsg') {
requires('java.logging')
requires('javafx.graphics')
requires('org.slf4j')
requires('vvecmath')
// Custom exports due to problems with other ext/samples/playground packages
exports('eu.mihosoft.jcsg')
exports('eu.mihosoft.jcsg.ext.imagej')
exports('eu.mihosoft.jcsg.ext.org.poly2tri')
exports('eu.mihosoft.jcsg.ext.quickhull3d')
}
// Transitive of org.fxyz3d:fxyz3d
module('org.orbisgis:poly2tri-core', 'poly2tri.core') {
requires('org.slf4j')
exportAllPackages()
}
module('com.github.quickhull3d:quickhull3d', 'quickhull3d') {
requires('org.slf4j')
exportAllPackages()
}
module('org.apache.commons:commons-math3', 'commons.math3') {
exportAllPackages()
}
// Transitive of org.zeromq:jeromq
module('eu.neilalexander:jnacl', 'jnacl') {
exportAllPackages()
}
module('com.github.sarxos:webcam-capture', 'webcam.capture') {
requires('java.desktop')
requires('jdk.unsupported')
requires('bridj')
requires('org.slf4j')
exportAllPackages()
}
// Transitive of com.github.sarxos:webcam-capture
module('com.nativelibs4java:bridj', 'bridj') {
exportAllPackages()
}
module('org.jflac:jflac-codec', 'jflac.codec') {
requires('java.desktop')
exportAllPackages()
}
}
// </editor-fold>
// ########################## TASKS Start ########################## //
// <editor-fold desp="Start Gradle Tasks">
// ########################## IDE Specific ########################## //
// <editor-fold desp="IDE Specific Tasks">
// https://youtrack.jetbrains.com/issue/IDEA-222172
idea {
module {
inheritOutputDirs = true
downloadJavadoc = true
downloadSources = true
}
}
tasks.named('wrapper', Wrapper) {
gradleVersion = '8.10.1'
distributionType = Wrapper.DistributionType.BIN
}
// </editor-fold>
// ########################## Java Specific ########################## //
// <editor-fold desp="Java Specific Tasks">
application {
mainModule = moduleName
mainClass = mainClassJarLauncher
}
java {
// sourceCompatibility = JavaVersion.VERSION_21 // Use this instead of toolchain.* if you want to manually setup your own JDK
// targetCompatibility = JavaVersion.VERSION_21 // Use this instead of toolchain.* if you want to manually setup your own JDK
toolchain.languageVersion = JavaLanguageVersion.of(21)
toolchain.vendor = JvmVendorSpec.ADOPTIUM
modularity.inferModulePath.set(true)
}
compileJava {
doFirst {
println "Compiler Args: $options.compilerArgs"
println "Runtime Classpath: ${sourceSets.main.runtimeClasspath.asPath.split(System.getProperty('path.separator'))}"
}
}
// List of Prism Settings
// https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/java/com/sun/prism/impl/PrismSettings.java
run {
jvmArgs += ['-Dprism.maxvram=2G', '-Djavafx.animation.fullspeed=true']
}
tasks.named('test', Test) {
useJUnitPlatform()
}
tasks.register('debug', JavaExec) {
dependsOn 'classes'
mainClass = mainClassPath
classpath = sourceSets.main.runtimeClasspath
debug true
}
// </editor-fold>
// ########################## Java FX Specific ########################## //
// <editor-fold desp="Java FX Specific Tasks">
javafx {
version = "$fxVersion"
modules = ['javafx.controls', 'javafx.fxml', 'javafx.swing', 'javafx.media']
}
// </editor-fold>
// ########################## Process Resource Files ########################## //
// <editor-fold desp="Process Resource Files">
// Allows adding title and version to build.properties resource file on compilation...
processResources {
def props = [
"trinity": [
"title" : artifactNameUpper,
"version" : project.version,
"revision" : versioning.info.build,
"timestamp": project.buildDate
]
]
filesMatching("**/build.properties") {
expand props
}
// Configure Default Logging Path (only applies when logback is enabled)
def logPath = "${artifactName}.log" // Note: if you update this make sure to verify/update fileNamePattern below as well
// Log to Console.App on OSX
if (isProdJlink && org.gradle.internal.os.OperatingSystem.current().macOsX) {
logPath = '${user.home}/Library/Logs/' + logPath
}
def logbackProps = [
"logging": [
"context": artifactNameUpper,
"path" : logPath,
"pattern": "${artifactName}-%d{yyyy-MM-dd}.%i.log",
"level" : '${LOGBACK_LOG_LEVEL:-INFO}'
]
]
filesMatching("**/logback.xml") {
expand logbackProps
}
}
// </editor-fold>
// ########################## Multi-Jar Tasks ########################## //
// <editor-fold desp="Multi-Jar Tasks">
// Might as well configure a decent manifest, even though we're not publishing this upstream...
tasks.withType(Jar).configureEach {
manifest {
attributes(
'Built-By': System.getProperty('user.name'),
'Created-By': "${System.getProperty('java.version')} (${System.getProperty('java.vendor')} ${System.getProperty('java.vm.version')})",
// https://docs.oracle.com/en/java/javase/20/docs/specs/jar/jar.html#main-attributes
'Main-Class': application.mainClass,
'Build-Date': project.buildDate,
'Build-Revision': versioning.info.commit,
'Specification-Title': project.name,
'Specification-Version': project.version,
'Implementation-Title': project.name,
'Implementation-Version': project.version,
// https://en.wikipedia.org/wiki/OSGi#Bundles
'Bundle-Name': project.name,
'Bundle-Version': project.version,
'Bundle-License': 'https://www.apache.org/licenses/LICENSE-2.0',
'Bundle-Description': project.description,
'Bundle-SymbolicName': application.mainModule,
)
}
// Exclude Signing Files
exclude 'META-INF/.RSA', 'META-INF/.SF', 'META-INF/*.DSA', 'META-INF/proguard/**'
// Exclude problematic duplicates (to avoid duplications strategy issues)
exclude 'META-INF/*LICENSE*', 'META-INF/*NOTICE*', 'META-INF/INDEX.LIST', 'META-INF/maven/**'
exclude 'META-INF/3rd-party-licenses/**', 'META-INF/substrate/**', 'LICENSE.txt'
// Include some top-level files for now...
from(layout.projectDirectory) {
include 'LICENSE.md', 'README.md'
}
}
// Cross Platform Build w/o Java FX
// Reference: https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_uber_jar_example
tasks.register('noFxUberJar', Jar) {
archiveClassifier = "no-fx"
duplicatesStrategy = DuplicatesStrategy.FAIL
from sourceSets.main.output
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.filter({ !(it.name =~ /javafx.*\.jar/) }).collect {
logger.quiet("Slim Jar: Including Dependency: {}", it.name)
it.isDirectory() ? it : zipTree(it)
}
} {
// Exclude problematic module-info.class duplicates from runtimeClasspath
exclude '**/module-info.class'
}
}
// Cross Platform Build w/ Java FX
tasks.register('fxUberJar', Jar) {
archiveClassifier = "fx"
duplicatesStrategy = DuplicatesStrategy.FAIL
from sourceSets.main.output
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.collect {
logger.quiet("Uber Jar: Including Dependency: {}", it.name)
it.isDirectory() ? it : zipTree(it)
}
} {
// Exclude problematic module-info.class duplicates from runtimeClasspath
exclude '**/module-info.class'
}
}
artifacts {
archives noFxUberJar
archives fxUberJar
}
// </editor-fold>
// ########################## JLINK / JPACKAGE ########################## //
// <editor-fold desp="JLINK / JPACKAGE">
// Modular Build (non cross platform)
jlink {
def fileSep = System.getProperty('file.separator')
def imageZipFile = layout.buildDirectory.file("${artifactNameUpper}-${project.version}.zip")
options.set(['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'])
imageZip.set(imageZipFile)
launcher {
name = artifactNameUpper
mainClass = mainClassPath
jvmArgs = ['-Dprism.maxvram=2G', '-Djavafx.animation.fullspeed=true']
jvmArgs += ["-Dlogback.configurationFile={{BIN_DIR}}${fileSep}logback.xml"]
//jvmArgs += ["--add-exports external.module.name/external.package.name=$sModuleName", ...]
}
//forceMerge('javafx')
//addExtraDependencies("javafx")
jpackage {
def currentOS = org.gradle.internal.os.OperatingSystem.current()
imageName = artifactNameUpper
appVersion = project.version.toString().replaceAll("-SNAPSHOT", "")
//resourceDir = file("$sourceSets.main.output.resourcesDir") // https://docs.oracle.com/en/java/javase/20/jpackage/override-jpackage-resources.html
imageOptions += ['--verbose']
jvmArgs = ['-Dprism.maxvram=2G', '-Djavafx.animation.fullspeed=true']
jvmArgs += ["-Dlogback.configurationFile=\$APPDIR${fileSep}logback.xml"]
jvmArgs += ['--module-path', '.']
if (currentOS.windows) {
skipInstaller = true
targetPlatformName = 'windows' // required when targetPlatform is used
// imageOptions += ['--win-console'] // only useful when we want to have a console launched with our app
// TODO
}
if (currentOS.macOsX) {
skipInstaller = true
targetPlatformName = 'osx' // required when targetPlatform is used
}
if (currentOS.linux) {
skipInstaller = false
targetPlatformName = 'linux-x64' // required when targetPlatform is used
// for menu group options, see https://specifications.freedesktop.org/menu-spec/latest/apa.html
// each value must be separated by ;, and final value must end with ;
installerType = null // generate both .deb and .rpm
installerOptions += ['--linux-shortcut', '--linux-menu-group', 'science;graphics;']
// TODO
}
println "targetPlatformName: " + targetPlatformName
}
}
// https://badass-jlink-plugin.beryx.org/releases/latest/#_properties
tasks.jlink.doLast {
copy {
from("$sourceSets.main.output.resourcesDir/logback.xml")
into("$imageDir/bin")
}
}
tasks.jpackageImage.doLast {
// Note: This runs right before jpackage
// https://docs.oracle.com/en/java/javase/20/jpackage/packaging-overview.html
def currentOS = org.gradle.internal.os.OperatingSystem.current()
def imageName = jpackageData.imageName
def outputDir = jpackageData.installerOutputDir
def image = currentOS.windows ? "$imageName/app" : currentOS.macOsX ? "${imageName}.app/Contents/app" : currentOS.linux ? "$imageName/lib/app" : ""
def copyTo = "$outputDir/$image"
copy {
from("$sourceSets.main.output.resourcesDir/logback.xml")
into layout.buildDirectory.dir(copyTo)
}
}
// </editor-fold>
// </editor-fold>
// ########################## TASKS END ########################## //