-
Notifications
You must be signed in to change notification settings - Fork 58
/
build.gradle.kts
483 lines (382 loc) · 16.3 KB
/
build.gradle.kts
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
/*
* Copyright 2024 dorkbox, llc
*
* 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
*
* http://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.
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import dorkbox.gradle.SwtType
import dorkbox.os.OS
///////////////////////////////
////// PUBLISH TO SONATYPE / MAVEN CENTRAL
////// TESTING : (to local maven repo) <'publish and release' - 'publishToMavenLocal'>
////// RELEASE : (to sonatype/maven central), <'publish and release' - 'publishToSonatypeAndRelease'>
///////////////////////////////
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS_FULL // always show the stacktrace!
plugins {
id("com.dorkbox.GradleUtils") version "3.18"
id("com.dorkbox.Licensing") version "2.28"
id("com.dorkbox.VersionUpdate") version "2.8"
id("com.dorkbox.GradlePublish") version "1.22"
id("com.github.johnrengelman.shadow") version "8.1.1"
kotlin("jvm") version "1.9.0"
}
// TODO: check if there are any images. ONLY if there are images, then we set all menu entries to have image offsets.
// otherwise, menus will be left-aligned.
object Extras {
// set for the project
const val description = "Cross-platform SystemTray support for Swing/AWT, GtkStatusIcon, and AppIndicator on Java 8+"
const val group = "com.dorkbox"
const val version = "4.5"
// set as project.ext
const val name = "SystemTray"
const val id = "SystemTray"
const val vendor = "Dorkbox LLC"
const val vendorUrl = "https://dorkbox.com"
const val url = "https://git.dorkbox.com/dorkbox/SystemTray"
}
///////////////////////////////
///// assign 'Extras'
///////////////////////////////
GradleUtils.load("$projectDir/../../gradle.properties", Extras)
GradleUtils.defaults()
GradleUtils.compileConfiguration(JavaVersion.VERSION_1_8)
GradleUtils.jpms(JavaVersion.VERSION_1_9)
licensing {
license(License.APACHE_2) {
description(Extras.description)
url(Extras.url)
author(Extras.vendor)
extra("Lantern", License.APACHE_2) {
copyright(2010)
author("Brave New Software Project, Inc.")
url("https://github.com/getlantern/lantern")
}
extra("QZTray", License.APACHE_2) {
copyright(2016)
author("Tres Finocchiaro")
author("QZ Industries, LLC")
url("https://github.com/tresf/tray/blob/dorkbox/src/qz/utils/ShellUtilities.java")
note("Partial code released as Apache 2.0 for use in the SystemTray project by dorkbox, llc. Used with permission.")
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
// this is incredibly verbose and repetitive, but the gradle dev team cannot figure out HOW they want gradle to behave, and is constantly
// changing -- so this is required to prevent compile warnings/errors.
val normalExampleCompile = configurations.create("normalExampleCompile").run { extendsFrom(configurations.compileClasspath.get()) }
val normalExampleConfig = configurations.create("normalExampleConfig").run { extendsFrom(normalExampleCompile) }
val javaFxExampleCompile = configurations.create("javaFxExampleCompile").run { extendsFrom(configurations.compileClasspath.get()) }
val javaFxExampleConfig = configurations.create("javaFxExampleConfig").run { extendsFrom(javaFxExampleCompile) }
val swtExampleCompile = configurations.create("swtExampleCompile").run { extendsFrom(configurations.compileClasspath.get()) }
val swtExampleConfig = configurations.create("swtExampleConfig").run { extendsFrom(swtExampleCompile) }
val linux64SwtDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
val mac64SwtDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
val macArm64SwtDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
val win64SwtDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
val normalExampleSet = sourceSets.create("normalExample")
val javaFxExampleSet = sourceSets.create("javaFxExample")
val swtExampleSet = sourceSets.create("swtExample")
fun SourceSetContainer.normalExample(block: SourceSet.() -> Unit) = normalExampleSet.apply(block)
fun SourceSetContainer.javaFxExample(block: SourceSet.() -> Unit) = javaFxExampleSet.apply(block)
fun SourceSetContainer.swtExample(block: SourceSet.() -> Unit) = swtExampleSet.apply(block)
sourceSets {
main {
java {
resources {
setSrcDirs(listOf("src"))
include("dorkbox/systemTray/gnomeShell/extension.js",
"dorkbox/systemTray/util/error_32.png")
}
}
kotlin {
setSrcDirs(listOf("src"))
}
}
normalExample {
java {
setSrcDirs(listOf("test-normal"))
// only want to include java files for the source. 'setSrcDirs' resets includes...
include("**/*.java")
}
kotlin {
setSrcDirs(listOf("test-normal"))
// only want to include kt files for the source. 'setSrcDirs' resets includes...
include("**/*.kt")
}
resources {
setSrcDirs(listOf("test-resources"))
include("dorkbox/*.png")
}
compileClasspath += sourceSets["main"].compileClasspath
runtimeClasspath += sourceSets["main"].runtimeClasspath
}
javaFxExample {
java {
setSrcDirs(listOf("test-javaFx"))
// only want to include java files for the source. 'setSrcDirs' resets includes...
include("**/*.java")
}
kotlin {
setSrcDirs(listOf("test-javaFx"))
// only want to include kt files for the source. 'setSrcDirs' resets includes...
include("**/*.kt")
}
resources {
setSrcDirs(listOf("test-resources"))
include("dorkbox/*.png")
}
compileClasspath += sourceSets["main"].compileClasspath
runtimeClasspath += sourceSets["main"].runtimeClasspath
}
swtExample {
java {
setSrcDirs(listOf("test-swt"))
// only want to include java files for the source. 'setSrcDirs' resets includes...
include("**/*.java")
}
kotlin {
setSrcDirs(listOf("test-swt"))
// only want to include kt files for the source. 'setSrcDirs' resets includes...
include("**/*.kt")
}
resources {
setSrcDirs(listOf("test-resources"))
include("dorkbox/*.png")
}
compileClasspath += sourceSets["main"].compileClasspath
runtimeClasspath += sourceSets["main"].runtimeClasspath
}
}
///////////////////////////////
////// Task defaults
///////////////////////////////
tasks.jar.get().apply {
manifest {
// https://docs.oracle.com/javase/tutorial/deployment/jar/packageman.html
attributes["Name"] = Extras.name
attributes["Specification-Title"] = Extras.name
attributes["Specification-Version"] = Extras.version
attributes["Specification-Vendor"] = Extras.vendor
attributes["Implementation-Title"] = "${Extras.group}.${Extras.id}"
attributes["Implementation-Version"] = GradleUtils.now()
attributes["Implementation-Vendor"] = Extras.vendor
}
}
dependencies {
val jnaVersion = "5.14.0"
// This is really SWT version 4.xx? no idea how the internal versions are tracked
// 4.4 is the oldest version that works with us, and the release of SWT is sPecIaL!
// 3.108.0 is the MOST RECENT version supported by x86. All newer version no longer support x86
// 3.1116.100 is the MOST RECENT version supported by macos ARM.
val swtVersion = "3.122.0"
api("com.dorkbox:Collections:2.8")
api("com.dorkbox:Executor:3.14")
api("com.dorkbox:Desktop:1.1")
api("com.dorkbox:JNA:1.4")
api("com.dorkbox:OS:1.11")
api("com.dorkbox:Updates:1.1")
api("com.dorkbox:Utilities:1.48")
api("org.javassist:javassist:3.30.1-GA")
api("net.java.dev.jna:jna-jpms:${jnaVersion}")
api("net.java.dev.jna:jna-platform-jpms:${jnaVersion}")
// note: this has support for JPMS, so it's required
api("org.slf4j:slf4j-api:1.8.0-beta4") // java 8
// api("org.slf4j:slf4j-api:2.0.9") // java 11 only
val logbackVer = "1.3.5" // java 8
// val logbackVer = "1.4.5" // java 11 only
// NOTE: we must have GRADLE ITSELF using the Oracle 1.8 JDK (which includes JavaFX).
// OR we will manually include JavaFx11 (JavaFx8, for what we use, is compatible)
// https://stackoverflow.com/questions/52569724/javafx-11-create-a-jar-file-with-gradle
// JavaFX isn't always added to the compile classpath....
// Java 8 includes JavaFX separately, Java11+ must use openjfx
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
// Paths for the various executables in the Java 'bin' directory
val javaFxFile = File("${System.getProperty("java.home", ".")}/lib/ext/jfxrt.jar")
println("\tJava 8, JavaFX: $javaFxFile")
if (javaFxFile.exists()) {
javaFxExampleCompile(files(javaFxFile))
} else {
println("\tJavaFX not found, unable to add JavaFX 8 dependency!")
}
} else {
// also see: https://stackoverflow.com/questions/52569724/javafx-11-create-a-jar-file-with-gradle
val currentOS = org.gradle.internal.os.OperatingSystem.current()
val platform = when {
currentOS.isWindows -> { "win" }
currentOS.isLinux -> { "linux" }
currentOS.isMacOsX -> {
if (OS.isArm) {
"mac-aarch64"
} else {
"mac"
}
}
else -> { "unknown" }
}
val version = "17.0.2"
println("\tJava ${JavaVersion.current()}, JavaFX: $version")
javaFxExampleCompile("org.openjfx:javafx-base:$version:${platform}")
javaFxExampleCompile("org.openjfx:javafx-graphics:$version:${platform}")
javaFxExampleCompile("org.openjfx:javafx-controls:$version:${platform}")
}
normalExampleCompile(sourceSets.main.get().output)
javaFxExampleCompile(sourceSets.main.get().output)
swtExampleCompile(sourceSets.main.get().output)
val logback = "ch.qos.logback:logback-classic:$logbackVer"
normalExampleCompile(logback)
javaFxExampleCompile(logback)
swtExampleCompile(logback)
linux64SwtDeps(logback)
mac64SwtDeps(logback)
macArm64SwtDeps(logback)
win64SwtDeps(logback)
// SEE: https://repo1.maven.org/maven2/org/eclipse/platform/
swtExampleCompile(GradleUtils.getSwtMavenId(swtVersion)) { isTransitive = false }
// add all SWT dependencies for all supported OS configurations to a "mega" jar
linux64SwtDeps(SwtType.LINUX_64.fullId(swtVersion)) { isTransitive = false }
mac64SwtDeps(SwtType.MAC_64.fullId(swtVersion)) { isTransitive = false }
macArm64SwtDeps(SwtType.MAC_AARCH64.fullId(swtVersion)) { isTransitive = false }
win64SwtDeps(SwtType.WIN_64.fullId(swtVersion)) { isTransitive = false }
linux64SwtDeps.resolutionStrategy {
dependencySubstitution {
substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
.using(module(SwtType.LINUX_64.fullId(swtVersion)))
}
}
mac64SwtDeps.resolutionStrategy {
dependencySubstitution {
substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
.using(module(SwtType.MAC_64.fullId(swtVersion)))
}
}
macArm64SwtDeps.resolutionStrategy {
dependencySubstitution {
substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
.using(module(SwtType.MAC_AARCH64.fullId(swtVersion)))
.because("SWT resolution is broken by default")
}
}
mac64SwtDeps.resolutionStrategy {
dependencySubstitution {
substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
.using(module(SwtType.WIN_64.fullId(swtVersion)))
}
}
}
/////////////////////////////
//// Tasks to launch examples from gradle
/////////////////////////////
task<JavaExec>("SystemTray_normal") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
classpath = normalExampleSet.runtimeClasspath
mainClass.set("dorkbox.TestTray")
standardInput = System.`in`
}
task<JavaExec>("SystemTray_javaFx") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
classpath = javaFxExampleSet.runtimeClasspath
mainClass.set("dorkbox.TestTrayJavaFX")
standardInput = System.`in`
}
task<JavaExec>("SystemTray_swt") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
classpath = swtExampleSet.runtimeClasspath
mainClass.set("dorkbox.TestTraySwt")
standardInput = System.`in`
jvmArgs = listOf("-XstartOnFirstThread")
}
///////////////////////////
// Jar Tasks
///////////////////////////
tasks.register<ShadowJar>("normalShadowJar") {
manifest.inheritFrom(tasks.jar.get().manifest)
group = "shadow"
manifest {
attributes["Main-Class"] = "dorkbox.TestTray"
}
mergeServiceFiles()
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(normalExampleSet.output)
configurations = listOf(normalExampleConfig)
archiveBaseName.set(project.name + "-Example")
}
tasks.register<ShadowJar>("javaFxShadowJar") {
manifest.inheritFrom(tasks.jar.get().manifest)
group = "shadow"
manifest {
attributes["Main-Class"] = "dorkbox.TestTrayJavaFX"
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
// necessary for java FX 8 on Java8, for our limited use - the api in JavaFx11 is compatible, so we can compile with any JDK
attributes["Class-Path"] = System.getProperty("java.home", ".") + "/lib/ext/jfxrt.jar"
}
}
mergeServiceFiles()
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(javaFxExampleSet.output)
configurations = listOf(javaFxExampleConfig)
archiveBaseName.set(project.name + "-JavaFxExample")
}
tasks.register<ShadowJar>("swtShadowJar") {
manifest.inheritFrom(tasks.jar.get().manifest)
group = "shadow"
manifest {
attributes["Main-Class"] = "dorkbox.TestTray"
}
mergeServiceFiles()
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// include ALL versions of SWT (so a single jar can run on all OS,
//// from(linux64SwtDeps.map { if (it.isDirectory) it else zipTree(it) }) {
//// exclude("META-INF/*.DSA", "META-INF/*.SF")
//// }
// from(mac64SwtDeps.map { if (it.isDirectory) it else zipTree(it) }) {
// exclude("META-INF/*.DSA", "META-INF/*.SF")
// }
// from(macArm64SwtDeps.map { if (it.isDirectory) it else zipTree(it) }) {
// exclude("META-INF/*.DSA", "META-INF/*.SF")
// }
//// from(win64SwtDeps.map { if (it.isDirectory) it else zipTree(it) }) {
//// exclude("META-INF/*.DSA", "META-INF/*.SF")
//// }
from(swtExampleSet.output)
configurations = listOf(swtExampleConfig)
exclude("META-INF/*.RSA", "META-INF/*.SF","META-INF/*.DSA")
archiveBaseName.set(project.name + "-SwtExample")
}
task("jarAllExamples") {
dependsOn("normalShadowJar")
dependsOn("javaFxShadowJar")
dependsOn("swtShadowJar")
group = "shadow"
description = "Create all-in-one examples for testing, using Java only, JavaFX, and SWT"
}
publishToSonatype {
groupId = Extras.group
artifactId = Extras.id
version = Extras.version
name = Extras.name
description = Extras.description
url = Extras.url
vendor = Extras.vendor
vendorUrl = Extras.vendorUrl
issueManagement {
url = "${Extras.url}/issues"
nickname = "Gitea Issues"
}
developer {
id = "dorkbox"
name = Extras.vendor
email = "email@dorkbox.com"
}
}