-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
215 lines (179 loc) · 6.31 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
215 lines (179 loc) · 6.31 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
import org.gradle.internal.os.OperatingSystem
plugins {
java
application
id("org.javamodularity.moduleplugin") version "1.8.15"
id("org.openjfx.javafxplugin") version "0.1.0"
id("org.beryx.jlink") version "3.1.3"
}
group = "org.example"
version = "1.3.0"
tasks.wrapper {
// Either download the binary-only version of Gradle (BIN) or
// the full version (with sources and documentation) of Gradle (ALL)
gradleVersion = "8.11.1"
distributionType = Wrapper.DistributionType.ALL
}
repositories {
mavenCentral()
}
val junitVersion = "5.10.3"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(17)
}
application {
mainModule.set("org.example.openccjavafx")
mainClass.set("org.example.openccjavafx.OpenccJavaFxApplication")
applicationDefaultJvmArgs = listOf(
"-Dfile.encoding=UTF-8",
"-XX:+IgnoreUnrecognizedVMOptions",
"--enable-native-access=javafx.graphics"
)
}
// Dev-only (optional). If you want run-task to match exactly:
tasks.withType<JavaExec> {
jvmArgs = application.applicationDefaultJvmArgs.toMutableList()
}
javafx {
version = "21.0.12"
modules("javafx.controls", "javafx.fxml")
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
implementation("org.fxmisc.richtext:richtextfx:0.11.7")
// JSON serialization/deserialization
// implementation(platform("com.fasterxml.jackson:jackson-bom:2.21.2"))
// implementation("com.fasterxml.jackson.core:jackson-databind")
// Core CLI parser
implementation("info.picocli:picocli:4.7.7")
annotationProcessor("info.picocli:picocli-codegen:4.7.7")
//PDFBox
implementation("org.apache.pdfbox:pdfbox:3.0.8")
// implementation("commons-logging:commons-logging:1.3.5")
// JSoup
implementation("org.jsoup:jsoup:1.22.1")
}
sourceSets {
test {
java.srcDirs("tests")
}
}
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "org.example.openccjavafx.OpenccJavaFxApplication"
}
}
tasks.test {
systemProperty("file.encoding", "utf-8")
useJUnitPlatform()
}
val os: OperatingSystem? = OperatingSystem.current()
val isWindows = os?.isWindows
val isMac = os?.isMacOsX
val isLinux = os?.isLinux
// Notes: Use --compress=zip-6 for JDK 21+, otherwise use 2
jlink {
imageZip = project.file("${layout.buildDirectory}/distributions/app-${javafx.platform.classifier}.zip")
options = listOf("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
launcher {
name = "OpenccJavaFX"
}
// ✅ Use this to tell jlink to include JavaFX modules
addExtraDependencies("javafx")
jpackage {
imageName = "OpenccJavaFX"
installerName = "OpenccJavaFX-Setup"
appVersion = project.version.toString()
// Choose installer type per OS (can override: -PinstallerType=deb|rpm|dmg|pkg|msi)
val overrideType = (findProperty("installerType") as String?)?.lowercase()
val targetType = overrideType ?: when {
isWindows == true -> "msi"
isMac == true -> "dmg" // or "pkg" if you prefer
else -> "deb" // linux default
}
installerType = targetType
// Allow overriding the installer output directory per invocation:
val outOverride = (findProperty("installerOut") as String?)?.trim()
if (!outOverride.isNullOrEmpty()) {
installerOutputDir = file(outOverride)
}
// Optional icon per OS (will use if the file exists)
val iconPath = when {
isWindows == true -> "src/main/jpackage/icon.ico"
isMac == true -> "src/main/jpackage/icon.icns"
else -> "src/main/jpackage/icon.png"
}
if (file(iconPath).exists()) {
icon = iconPath
}
// OS-specific installer options
// IMPORTANT: add DEB maintainer (and a friendly linux package name)
installerOptions = when {
isWindows == true -> listOf("--win-menu", "--win-shortcut", "--win-dir-chooser")
isMac == true -> listOf("--mac-package-identifier", "org.example.openccjavafx")
else -> listOf(
"--verbose",
"--linux-shortcut",
"--linux-package-name", "openccjavafx",
"--linux-deb-maintainer", "Laisuk Lai <laisuk@users.noreply.github.com>",
"--vendor", "OpenccJavaFX",
"--linux-app-category", "Utility"
)
}
// Optional: include external dicts folder in the final package
// Keep resources (e.g., desktop files/icons)
resourceDir = file("src/main/jpackage")
}
}
val appImageRoot: Provider<Directory> = layout.buildDirectory.dir(
if (isMac == true) "jpackage/OpenccJavaFX.app/Contents/app"
else "jpackage/OpenccJavaFX"
)
// Put dicts into the actual app-image for each OS
tasks.register<Copy>("copyDicts") {
description = "Put dicts into the actual app-image for each OS"
dependsOn("jpackageImage")
from("dicts")
into(appImageRoot.map { it.dir("dicts") })
}
tasks.named("jpackage").configure {
dependsOn("copyDicts")
}
tasks.named("copyDicts") {
mustRunAfter("jpackageImage")
}
// Zip the correct app-image path (bundle on macOS, folder elsewhere)
tasks.register<Zip>("zipAppImage") {
description = "Zip the correct app-image path (bundle on macOS, folder elsewhere)"
dependsOn("jpackageImage", "copyDicts")
destinationDirectory.set(layout.buildDirectory.dir("distributions"))
archiveFileName.set("OpenccJavaFX-portable.zip")
from(if (isMac == true) "build/jpackage/OpenccJavaFX.app" else "build/jpackage/OpenccJavaFX")
}
tasks.named("jlinkZip") {
group = "distribution"
}
distributions {
main {
contents {
from("dicts") {
into("dicts")
}
from("bin/openccjava-cli.bat") {
into("bin")
}
from("bin/openccjava-cli") {
into("bin")
filePermissions {
unix("0755") // Sets permissions to rwxr-xr-x
}
}
}
}
}