-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbuild.gradle
More file actions
274 lines (229 loc) · 9.13 KB
/
build.gradle
File metadata and controls
274 lines (229 loc) · 9.13 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
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import java.lang.module.ModuleFinder
import java.util.stream.Stream
plugins {
id 'org.gradlex.extra-java-module-info' version '1.13.1' apply false
id("com.diffplug.spotless") version "8.0.0" apply false
id 'de.undercouch.download' version '5.6.0'
}
allprojects { subproject ->
apply plugin: 'org.gradlex.extra-java-module-info'
extraJavaModuleInfo {
failOnMissingModuleInfo.set(true)
}
apply from: "$rootDir/gradle/gradle_scripts/modules.gradle"
// https://docs.gradle.org/9.0.0/userguide/upgrading_major_version_9.html#reproducible_archives_by_default
tasks.withType(AbstractArchiveTask).configureEach {
reproducibleFileOrder = false
preserveFileTimestamps = true
useFileSystemPermissions()
}
}
subprojects {subproject ->
if (subproject.name == 'dist') {
return
}
apply plugin: 'com.diffplug.spotless'
spotless {
java {
palantirJavaFormat()
trimTrailingWhitespace()
endWithNewline()
importOrder(groupName, 'javafx', '', 'java', '\\#')
}
}
}
// Project variable functions
static def getArchName() {
var arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT)
if (arch == 'amd64' || arch == 'x86_64') {
return 'x86_64'
}
if (arch == 'arm' || arch == 'aarch64') {
return 'arm64'
}
if (arch == 'x86') {
return 'x86'
}
return arch
}
def getJvmArgs() {
def os = DefaultNativePlatform.currentOperatingSystem
def jvmRunArgs = [
"-Dvisualvm.display.name=$productName",
"-Djavafx.preloader=" + packageName("core.AppPreloader"),
"-Djdk.virtualThreadScheduler.parallelism=8"
]
// Virtual threads cause crashes on Windows ARM with Liberica
if (os.isWindows() && arch == "arm64") {
jvmRunArgs += [
"-D" + propertyName("useVirtualThreads") + "=false"
]
}
// Disable JDK24+ warnings
jvmRunArgs += [
"--enable-native-access=com.sun.jna",
"--enable-native-access=javafx.graphics",
"--enable-native-access=javafx.web",
"--sun-misc-unsafe-memory-access=allow",
"--enable-native-access=javafx.media",
"--enable-native-access=com.github.kwhat.jnativehook",
"--enable-native-access=org.graalvm.truffle"
]
// Module access fixes
def appPackage = packageName(null)
jvmRunArgs += [
"--add-exports", "javafx.graphics/com.sun.javafx.tk=$appPackage",
"--add-exports", "jdk.zipfs/jdk.nio.zipfs=io.xpipe.modulefs",
"--add-opens", "java.desktop/java.awt.image=$appPackage",
"--add-opens", "javafx.graphics/com.sun.glass.ui=$appPackage",
"--add-opens", "javafx.graphics/javafx.stage=$appPackage",
"--add-opens", "javafx.graphics/com.sun.javafx.tk=$appPackage",
"--add-opens", "javafx.graphics/com.sun.javafx.tk.quantum=$appPackage"
]
jvmRunArgs += [
"--add-exports", "javafx.graphics/com.sun.javafx.scene=com.jfoenix",
"--add-exports", "javafx.graphics/com.sun.javafx.stage=com.jfoenix",
"--add-exports", "javafx.base/com.sun.javafx.binding=com.jfoenix",
"--add-exports", "javafx.base/com.sun.javafx.event=com.jfoenix",
"--add-exports", "javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
"--add-exports", "javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
"--add-opens", "java.base/java.lang.reflect=com.jfoenix"
]
// Use project liliput
jvmRunArgs += ['-XX:+UseCompactObjectHeaders']
// Reduce heap usage with deduplication
jvmRunArgs += ['-XX:+UseStringDeduplication']
// GC config
jvmRunArgs += ['-XX:+UseG1GC',
'-Xms300m',
'-Xmx16G',
'-XX:MinHeapFreeRatio=20',
'-XX:MaxHeapFreeRatio=30',
'-XX:GCTimeRatio=9',
// The default makes GC pauses longer for some reason
// on older Windows systems
'-XX:G1HeapRegionSize=4m'
]
// Fix platform theme detection on macOS
if (os.isMacOsX()) {
jvmRunArgs += ["-Dapple.awt.application.appearance=system"]
}
if (os.isMacOsX()) {
jvmRunArgs += "-Xdock:name=$productName"
}
// Why is this not on by default? ...
// https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/doc-files/net-properties.html
jvmRunArgs += [
'-Djava.net.useSystemProxies=true'
]
return jvmRunArgs
}
def getWindowsSchemaCanonicalVersion() {
def v = canonicalVersionString
def last = 0
if (v.split("\\.").length == 2) {
v = v + ".0"
}
return v + "." + last
}
// https://stackoverflow.com/questions/79720795/replacing-deprecated-projectexec-in-dofirst-dolast
interface InjectedExecOps {
@javax.inject.Inject
ExecOperations getExecOps()
}
// Project variables
project.ext {
// Enable release pipeline if variable is present
isFullRelease = Boolean.parseBoolean(System.getenv('RELEASE'))
// Check if in build pipeline
ci = System.getenv('CI') != null
// Create AOT cache for runtime image only in build pipeline
enableAot = ci
// Names of your app
productName = 'Pdx-Unlimiter'
kebapProductName = 'pdx-unlimiter'
snakeProductName = 'pdx_unlimiter'
// The names of your packages
groupName = 'com.crschnick'
artifactName = 'pdxu.app'
// The base name of the generated packages
distName = "pdx-unlimiter"
// Version info
rawVersion = file('version').text.strip()
versionString = rawVersion + (isFullRelease ? '' : '-SNAPSHOT')
versionReleaseNumber = rawVersion.split('-').length == 2 ? Integer.parseInt(rawVersion.split('-')[1]) : 1
canonicalVersionString = rawVersion.split('-').length == 2 ? rawVersion.split('-')[0] : rawVersion
buildId = UUID.nameUUIDFromBytes(versionString.getBytes())
windowsSchemaCanonicalVersion = getWindowsSchemaCanonicalVersion()
// GPG signing config
signingEnabled = true
signingKeyId = System.getenv('GPG_KEY_ID') != null ? System.getenv('GPG_KEY_ID') : ""
signingKey = System.getenv('GPG_KEY') != null ? System.getenv('GPG_KEY') : ""
signingPassword =System.getenv('GPG_KEY_PASSWORD') != null ? System.getenv('GPG_KEY_PASSWORD') : ""
// Build config
os = org.gradle.internal.os.OperatingSystem.current()
arch = getArchName()
jvmRunArgs = getJvmArgs()
// JPackage config
jpackageExecutableName = distName
jpackageMacOsBundleName = "${groupName.replaceAll("_", "-")}.${artifactName.replaceAll("_", "-")}"
jpackageReleaseArguments = jvmRunArgs + [
"-D" + propertyName("version") + "=" + versionString,
"-D" + propertyName("build") + "=$versionString/${new Date().format('yyyy-MM-dd-HH-mm')}",
"-D" + propertyName("buildId") + "=" + buildId
]
// Make sure that the dynamic library from jna is loaded without any extraction
jpackageReleaseArguments += [
'-Djna.nosys=false',
'-Djna.nounpack=true',
'-Djna.noclasspath=true'
]
if (isFullRelease) {
// Prevent debugger attach in production release
jpackageReleaseArguments += "-XX:+DisableAttachMechanism"
}
// JavaFX config
// Development and production javafx versions can be different
// Dev uses the maven dependencies and production uses jmods
// unless jdkHasBundledJavaFx is set to true
devJavafxVersion = '27-ea+4'
productionJavafxVersion = '27-ea+4'
jdkHasBundledJavaFx = ModuleFinder.ofSystem().find("javafx.base").isPresent()
// Define a custom JavaFX SDK location to use custom JavaFX jars instead of the default one
customJavaFxPath = null
sentryUrl = "https://cff56f4c1d624f46b64f51a8301d3543@sentry.io/5466262"
if (sentryUrl != null) {
jpackageReleaseArguments += "-D" + propertyName("sentryUrl") + "=" + sentryUrl
}
def injected = project.objects.newInstance(InjectedExecOps)
execOps = injected.execOps;
}
group = groupName
version = versionString
// Global helper functions
def propertyName(String s) {
return groupName + "." + artifactName + "." + s
}
def packageName(String s) {
return groupName + "." + artifactName + (s != null ? "." + s : "")
}
def replaceVariablesInFile(String f, Map<String, String> replacements) {
def fileName = file(f).getName()
def text = file(f).text
def replaced = text.replace(replacements)
def build = "${project.layout.buildDirectory.get()}/${UUID.randomUUID()}"
file(build).mkdirs()
def temp = "$build/$fileName"
file(temp).text = replaced
return file(temp)
}
// Developer config file setup
var devProps = file("$rootDir/pdxu-app/dev.properties")
if (!devProps.exists()) {
devProps.text = file("$rootDir/gradle/gradle_scripts/dev_default.properties").text
}
// Checks
if (System.getProperty("java.home").contains(" ")) {
throw new IllegalArgumentException("Your JDK home path contains spaces. This will break several gradle plugins")
}