forked from dorkbox/SystemTray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
439 lines (355 loc) · 14.9 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
/*
* Copyright 2023 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 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"
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.")
}
}
}
val exampleCompile by configurations.creating { extendsFrom(configurations.implementation.get()) }
val javaFxExampleCompile : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
val swtExampleCompile : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
//val javaFxDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
//val linux64SwtDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
//val mac64SwtDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
//val win64SwtDeps : Configuration by configurations.creating { extendsFrom(configurations.implementation.get()) }
val SourceSetContainer.javaFxExample: SourceSet get() = maybeCreate("javaFxExample")
fun SourceSetContainer.javaFxExample(block: SourceSet.() -> Unit) = javaFxExample.apply(block)
val SourceSetContainer.swtExample: SourceSet get() = maybeCreate("swtExample")
fun SourceSetContainer.swtExample(block: SourceSet.() -> Unit) = swtExample.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"))
}
}
test {
resources {
setSrcDirs(listOf("test"))
include("dorkbox/*.png")
}
compileClasspath += sourceSets["main"].runtimeClasspath
}
javaFxExample {
java {
setSrcDirs(listOf("test-javaFx"))
// only want to include java files for the source. 'setSrcDirs' resets includes...
include("**/*.java")
// this is required because we reset the srcDirs to 'test' above, and 'main' must manually be added back
srcDir(sourceSets["main"].allJava)
}
resources {
setSrcDirs(listOf("test"))
include("dorkbox/*.png")
srcDir(sourceSets["main"].resources)
}
compileClasspath += sourceSets["test"].runtimeClasspath
}
swtExample {
java {
setSrcDirs(listOf("test-swt"))
// only want to include java files for the source. 'setSrcDirs' resets includes...
include("**/*.java")
srcDir(sourceSets["main"].allJava)
}
resources {
setSrcDirs(listOf("test"))
include("dorkbox/*.png")
srcDir(sourceSets["main"].resources)
}
compileClasspath += sourceSets["test"].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.13.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.7")
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.29.2-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.7") // java 11 only
val logbackVer = "1.3.5" // java 8
// val logbackVer = "1.4.5" // java 11 only
// api("ch.qos.logback:logback-classic:$logbackVer")
// 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"
javaFxExampleCompile("org.openjfx:javafx-base:$version:${platform}")
javaFxExampleCompile("org.openjfx:javafx-graphics:$version:${platform}")
javaFxExampleCompile("org.openjfx:javafx-controls:$version:${platform}")
// // include all distro for jars
// listOf("win", "linux", "mac").forEach {
// javaFxDeps("org.openjfx:javafx-base:11:${it}")
// javaFxDeps("org.openjfx:javafx-graphics:11:${it}")
// javaFxDeps("org.openjfx:javafx-controls:11:${it}")
// }
}
// SEE: https://repo1.maven.org/maven2/org/eclipse/platform/
swtExampleCompile(GradleUtils.getSwtMavenId(swtVersion)) {
isTransitive = false
}
val log = testImplementation("ch.qos.logback:logback-classic:$logbackVer")!!
exampleCompile.dependencies += log
javaFxExampleCompile.dependencies += log
swtExampleCompile.dependencies += log
// // add all SWT dependencies for all supported OS configurations to a "mega" jar
// linux64SwtDeps(SwtType.LINUX_64.fullId(Extras.swtVersion)) { isTransitive = false }
// mac64SwtDeps(SwtType.MAC_64.fullId(Extras.swtVersion)) { isTransitive = false }
// win64SwtDeps(SwtType.WIN_64.fullId(Extras.swtVersion)) { isTransitive = false }
//
// linux64SwtDeps.dependencies += log
// mac64SwtDeps.dependencies += log
// win64SwtDeps.dependencies += log
//
// linux64SwtDeps.resolutionStrategy {
// dependencySubstitution {
// substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
// .with(module(SwtType.LINUX_64.fullId(Extras.swtVersion)))
// }
// }
// mac64SwtDeps.resolutionStrategy {
// dependencySubstitution {
// substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
// .with(module(SwtType.MAC_64.fullId(Extras.swtVersion)))
// }
// }
// mac64SwtDeps.resolutionStrategy {
// dependencySubstitution {
// substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
// .with(module(SwtType.WIN_64.fullId(Extras.swtVersion)))
// }
// }
}
/////////////////////////////
//// Tasks to launch examples from gradle
/////////////////////////////
task<JavaExec>("SystemTray_default") {
group = BasePlugin.BUILD_GROUP
classpath = sourceSets["test"].runtimeClasspath
mainClass.set("dorkbox.TestTray")
standardInput = System.`in`
}
task<JavaExec>("SystemTray_javaFx") {
group = BasePlugin.BUILD_GROUP
classpath = sourceSets.javaFxExample.runtimeClasspath
mainClass.set("dorkbox.TestTrayJavaFX")
standardInput = System.`in`
}
task<JavaExec>("SystemTray_swt") {
group = BasePlugin.BUILD_GROUP
classpath = sourceSets.swtExample.runtimeClasspath
mainClass.set("dorkbox.TestTraySwt")
standardInput = System.`in`
jvmArgs = listOf("-XstartOnFirstThread")
}
///////////////////////////
// Jar Tasks
///////////////////////////
task<Jar>("jarExample") {
archiveBaseName.set("SystemTray-Example")
group = BasePlugin.BUILD_GROUP
description = "Create an all-in-one example for testing, on a standard Java installation"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
outputs.upToDateWhen { false }
from(sourceSets["main"].output)
from(sourceSets["test"].output)
from(exampleCompile.map { if (it.isDirectory) it else zipTree(it) }) {
exclude("META-INF/*.DSA", "META-INF/*.SF")
}
manifest {
attributes["Main-Class"] = "dorkbox.TestTray"
}
}
task<Jar>("jarJavaFxExample") {
archiveBaseName.set("SystemTray-JavaFxExample")
group = BasePlugin.BUILD_GROUP
description = "Create an all-in-one example for testing, using JavaFX"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
outputs.upToDateWhen { false }
from(sourceSets["main"].output)
from(sourceSets.javaFxExample.output)
// from(javaFxExampleCompile.map { if (it.isDirectory) it else zipTree(it) }) {
// exclude("META-INF/*.DSA", "META-INF/*.SF")
// }
// from(javaFxDeps.map { if (it.isDirectory) it else zipTree(it) }) {
// exclude("META-INF/*.DSA", "META-INF/*.SF")
// }
manifest {
attributes["Main-Class"] = "dorkbox.TestTrayJavaFX"
// 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"
}
}
task<Jar>("jarSwtExample") {
archiveBaseName.set("SystemTray-SwtExample")
group = BasePlugin.BUILD_GROUP
description = "Create an all-in-one example for testing, using SWT"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
outputs.upToDateWhen { false }
from(sourceSets["main"].output)
from(sourceSets.swtExample.output)
// from(swtExampleCompile.map { if (it.isDirectory) it else zipTree(it) }) {
// exclude("META-INF/*.DSA", "META-INF/*.SF")
// }
// 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(win64SwtDeps.map { if (it.isDirectory) it else zipTree(it) }) {
// exclude("META-INF/*.DSA", "META-INF/*.SF")
// }
manifest {
attributes["Main-Class"] = "dorkbox.TestTraySwt"
}
}
task("jarAllExamples") {
dependsOn("jarExample")
dependsOn("jarJavaFxExample")
dependsOn("jarSwtExample")
group = BasePlugin.BUILD_GROUP
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 protected]"
}
}