-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathbuild.gradle
More file actions
324 lines (301 loc) · 10.8 KB
/
build.gradle
File metadata and controls
324 lines (301 loc) · 10.8 KB
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
plugins {
id 'java'
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.12'
id 'org.openjfx.javafxplugin' version '0.1.0'
id 'org.beryx.jlink' version '3.1.5'
id 'org.gradlex.extra-java-module-info' version '1.12'
}
// 读取配置文件
def xProps = new Properties()
def versionPropsFile = file("${projectDir}/src/main/resources/x.properties")
if (versionPropsFile.exists()) {
xProps.load(new FileInputStream(versionPropsFile))
} else {
throw new GradleException("x.properties file not found!")
}
// 获取版本信息
def buildVersion = xProps.getProperty('app-version', '1.0.0')
group 'io.knifer'
version buildVersion
repositories {
mavenCentral()
}
sourceCompatibility = '17'
targetCompatibility = '17'
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
application {
mainModule = 'io.knifer.freebox'
mainClass = 'io.knifer.freebox.FreeBoxApplication'
}
javafx {
// 对于arm64架构的linux,JavaFX社区尚未提供21.0.1版本之后的发布
version = org.gradle.internal.os.OperatingSystem.current().linux &&
getCurrentArch() == 'arm64' ?
'21.0.1'
:
'21.0.9'
modules = ['javafx.controls', 'javafx.fxml']
}
ext {
dv = [
controlsFX: '11.2.2',
ikonli: '12.3.1',
gson: '2.11.0',
guava: '33.2.1-jre',
lang3: '3.16.0',
javaWebSocket: '1.6.0',
tinylog: '2.7.0',
blockingMap: '0.91',
vlcjJavaFX: '1.2.0',
vlcj: '4.8.3',
filelize: '0.9.5',
m3uParser: '1.4.0',
okhttp: '5.0.0-alpha.14',
hutool: '5.8.43',
jsoup: '1.15.3',
jsoupXpath: '2.5.1',
json: '20250517',
zxingCore: '3.5.3',
twelvemonkeys: '3.12.0',
emojiJava: '5.1.1',
mpv: '0.1.3',
graal: '24.2.2',
kotlinxCoroutines: '1.8.1',
guice: '7.0.0',
lombok: '1.18.34',
junit: '5.9.2'
]
}
dependencies {
implementation "org.controlsfx:controlsfx:${dv.controlsFX}"
implementation "org.kordamp.ikonli:ikonli-javafx:${dv.ikonli}"
implementation "org.kordamp.ikonli:ikonli-fontawesome-pack:${dv.ikonli}"
implementation "com.google.code.gson:gson:${dv.gson}"
implementation "com.google.guava:guava:${dv.guava}"
implementation "org.apache.commons:commons-lang3:${dv.lang3}"
implementation "org.java-websocket:Java-WebSocket:${dv.javaWebSocket}"
implementation "org.tinylog:slf4j-tinylog:${dv.tinylog}"
implementation "org.tinylog:tinylog-impl:${dv.tinylog}"
implementation "com.github.sarveswaran-m:util.concurrent.blockingMap:${dv.blockingMap}"
implementation "uk.co.caprica:vlcj:${dv.vlcj}"
implementation "uk.co.caprica:vlcj-javafx:${dv.vlcjJavaFX}"
implementation "io.github.filelize:filelize-java:${dv.filelize}"
implementation "com.github.bjoernpetersen:m3u-parser:${dv.m3uParser}"
implementation "com.squareup.okhttp3:okhttp:${dv.okhttp}"
implementation "cn.hutool:hutool-core:${dv.hutool}"
implementation "cn.hutool:hutool-crypto:${dv.hutool}"
implementation "cn.hutool:hutool-http:${dv.hutool}"
implementation "cn.hutool:hutool-json:${dv.hutool}"
implementation "cn.hutool:hutool-system:${dv.hutool}"
implementation "org.jsoup:jsoup:${dv.jsoup}"
implementation "cn.wanghaomiao:JsoupXpath:${dv.jsoupXpath}"
implementation "org.json:json:${dv.json}"
implementation "com.google.zxing:core:${dv.zxingCore}"
implementation "com.twelvemonkeys.imageio:imageio-webp:${dv.twelvemonkeys}"
implementation "com.twelvemonkeys.imageio:imageio-jpeg:${dv.twelvemonkeys}"
implementation "com.vdurmont:emoji-java:${dv.emojiJava}"
implementation("io.github.kknifer7:mpv:${dv.mpv}") {
// vlcj依赖中已包含模块化的高版本jna,所以这里排除
exclude group: 'net.java.dev.jna'
// 排除日志依赖,统一使用tinylog
exclude module: 'slf4j-simple'
}
implementation "org.graalvm.polyglot:polyglot:${dv.graal}"
implementation "org.graalvm.js:js-language:${dv.graal}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${dv.kotlinxCoroutines}"
implementation "com.google.inject:guice:${dv.guice}"
compileOnly "org.projectlombok:lombok:${dv.lombok}"
annotationProcessor "org.projectlombok:lombok:${dv.lombok}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${dv.junit}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${dv.junit}"
testCompileOnly "org.projectlombok:lombok:${dv.lombok}"
testAnnotationProcessor "org.projectlombok:lombok:${dv.lombok}"
}
extraJavaModuleInfo {
/* 处理非模块化项目、解决模块化相关问题 */
// javafx controlsFX
module('org.openjfx:javafx-base', 'javafx.base') {
patchRealModule()
exportAllPackages()
}
// okhttp、kotlin
module('org.jetbrains.kotlin:kotlin-stdlib', 'kotlin.stdlib') {
patchRealModule()
exportAllPackages()
}
module('org.jetbrains:annotations', 'annotations') {
patchRealModule()
exportAllPackages()
}
// filelize
module('io.github.filelize:filelize-java', 'filelize') {
requires 'org.slf4j'
requires 'com.fasterxml.jackson.databind'
exportAllPackages()
}
// 解决mpv依赖找不到jna-platform的问题
module('org.scala-sbt.ipcsocket:ipcsocket', 'ipcsocket') {
patchRealModule()
requires 'com.sun.jna'
requires 'com.sun.jna.platform'
exports 'org.scalasbt.ipcsocket'
}
/* 自动处理非模块化项目 */
// blockingMap
automaticModule('com.github.sarveswaran-m:util.concurrent.blockingMap', 'blockingMap4j')
// 解决google guava相关的编译错误
automaticModule('com.google.guava:listenablefuture', 'listenablefutureAvoidConflict')
automaticModule('com.google.code.findbugs:jsr305', 'jsr305')
// JsoupXpath
automaticModule('cn.wanghaomiao:JsoupXpath', 'jsoupXpath')
// mpv
automaticModule('io.github.kknifer7:mpv', 'mpv')
// emoji-java
automaticModule('com.vdurmont:emoji-java', 'emojiJava')
// guice
automaticModule('aopalliance:aopalliance', 'aopalliance')
}
test {
useJUnitPlatform()
}
def isPackaging = gradle.startParameter.taskNames.contains('jpackage')
sourceSets {
main {
resources {
srcDirs = ['src/main/resources']
if (isPackaging) {
exclude 'tinylog-dev.properties'
}
}
}
}
clean {
delete "${projectDir}/jpackage_temp"
}
jar {
manifest {
attributes = [
'Main-Class': application.mainClass
]
}
}
run {
jvmArgs = [
'--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls',
'--add-opens=org.controlsfx.controls/org.controlsfx.control=io.knifer.freebox',
'--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls',
'--add-opens=javafx.graphics/javafx.scene.text=cn.hutool.core',
'--add-opens=org.tinylog.api/org.tinylog.configuration=io.knifer.freebox',
'-Dpolyglot.engine.WarnInterpreterOnly=false'
]
if (isPackaging) {
jvmArgs += [
'--add-opens=javafx.graphics/javafx.scene.text=io.knifer.merged.module',
'-Dfreebox.profile=PROD'
]
} else {
jvmArgs += '-Dfreebox.profile=DEV'
}
}
def appDisplayName = 'FreeBox'
jlink {
imageZip = project.file(resolveBuildDir("/distributions/app-${javafx.platform.classifier}.zip"))
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = appDisplayName
jvmArgs = run.jvmArgs
}
mergedModule {
requires 'java.sql'
requires 'java.logging'
requires 'java.desktop'
requires 'java.naming'
requires 'java.management'
requires 'jdk.httpserver'
requires 'jdk.crypto.ec'
requires 'org.slf4j'
requires 'org.json'
requires 'com.google.gson'
requires 'ipcsocket'
requires 'kotlin.stdlib'
requires 'jakarta.inject'
uses 'cn.hutool.core.convert.Converter'
}
tasks.named('jlink') {
doLast {
copy {
from "${projectDir}/resources/app-assets"
into imageDir
}
}
}
tasks.named('jpackage') {
doFirst {
delete "${projectDir}/jpackage_temp"
}
}
jpackage {
mainClassName = application.mainClass
installerName = launcherName
installerType = project.hasProperty('jpackage.installerType') ?
project.getProperties().get('jpackage.installerType') :
'msi'
appVersion = project.version
vendor = 'knifer'
installerOptions = [
'--verbose',
'--temp', 'jpackage_temp'
]
if (org.gradle.internal.os.OperatingSystem.current().windows) {
icon = "${projectDir}/resources/logo/FreeBox.ico"
installerOptions += [
'--win-dir-chooser',
'--win-menu',
'--win-shortcut',
'--win-shortcut-prompt',
'--win-upgrade-uuid', '8EA2474F-D1AB-A3A7-CD9A-ED7895F4CAA4',
'--resource-dir', "${projectDir}/resources/wix"
]
if ('true' == xProps.get('debug')) {
imageOptions = ['--win-console']
}
} else if (org.gradle.internal.os.OperatingSystem.current().linux) {
icon = "${projectDir}/resources/logo/FreeBox.png"
installerOptions += [
'--linux-package-name', 'freebox',
'--linux-shortcut',
'--linux-deb-maintainer', 'knifer@duck.com',
'--linux-menu-group', 'AudioVideo;Audio;Video;',
'--linux-app-category', 'video;',
'--linux-rpm-license-type', 'GPL-3.0-only',
'--resource-dir', "${projectDir}/resources/logo"
]
installerOptions += ['--linux-app-release', getCurrentArch()]
} else if (org.gradle.internal.os.OperatingSystem.current().macOsX) {
icon = "${projectDir}/resources/logo/FreeBox.icns"
installerOptions += [
'--mac-app-category', 'public.app-category.video'
]
}
}
}
jlinkZip {
group = 'distribution'
}
private String resolveBuildDir(String dir) {
return layout.buildDirectory.get().dir(dir)
}
private static def getCurrentArch() {
String arch = System.getProperty("os.arch")
switch (arch) {
case "x86_64":
return "amd64"
case "aarch64":
return "arm64"
default:
return arch
}
}