Created
January 7, 2025 11:24
-
-
Save fusetim/f5565a44b8de482e258c1259938dafcb to your computer and use it in GitHub Desktop.
JavaFX ShadowJar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '2.25.0' | |
id 'com.diffplug.spotless' version '6.25.0' | |
id "com.github.johnrengelman.shadow" version "8.1.1" | |
} | |
group 'eu.telecomnancy' | |
version '0.0.1' | |
repositories { | |
mavenCentral() | |
} | |
ext { | |
junitVersion = '5.10.0' | |
} | |
sourceCompatibility = '21' | |
targetCompatibility = '21' | |
tasks.withType(JavaCompile) { | |
options.encoding = 'UTF-8' | |
} | |
application { | |
mainModule = 'eu.telecomnancy.codechill' | |
mainClass = 'eu.telecomnancy.codechill.CodechillApplication' | |
} | |
javafx { | |
version = '21' | |
modules = ['javafx.controls', 'javafx.fxml'] | |
} | |
dependencies { | |
// QRCode library -- https://github.com/woo-j/OkapiBarcode | |
implementation 'uk.org.okapibarcode:okapibarcode:0.4.9' | |
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}") | |
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}") | |
compileOnly 'org.projectlombok:lombok:1.18.36' | |
annotationProcessor 'org.projectlombok:lombok:1.18.36' | |
testCompileOnly 'org.projectlombok:lombok:1.18.36' | |
testAnnotationProcessor 'org.projectlombok:lombok:1.18.36' | |
} | |
test { | |
useJUnitPlatform() | |
} | |
jlink { | |
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip") | |
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'] | |
launcher { | |
name = 'app' | |
} | |
} | |
jlinkZip { | |
group = 'distribution' | |
} | |
spotless { | |
// optional: limit format enforcement to just the files changed by this feature branch | |
// ratchetFrom 'origin/develop' | |
format 'misc', { | |
// define the files to apply `misc` to | |
target '*.gradle', '.gitattributes', '.gitignore' | |
// define the steps to apply to those files | |
trimTrailingWhitespace() | |
indentWithSpaces(4) | |
endWithNewline() | |
} | |
java { | |
eclipse().configFile("formatting.xml") | |
} | |
} | |
// ShadowJar configuration | |
tasks.named('shadowJar') { | |
dependencies { | |
exclude(dependency('org.openjfx:javafx.controls')) | |
exclude(dependency('org.openjfx:javafx.fxml')) | |
exclude(dependency('org.openjfx:javafx.graphics')) | |
exclude(dependency('org.openjfx:javafx.base')) | |
} | |
// Other shadow jar options (optional) | |
mergeServiceFiles() | |
manifest { | |
attributes 'Main-Class': 'eu.telecomnancy.codechill.CodechillApplication' | |
} | |
} | |
tasks.named('runShadow') { | |
doFirst { | |
// Get the runtime classpath for JavaFX dependencies | |
def javafxClasspath = configurations.runtimeClasspath.files.collect { it.absolutePath }.join(File.pathSeparator) | |
// Ensure JavaFX modules are added to the module path for running the application | |
jvmArgs = [ | |
'--module-path', javafxClasspath, // Ensure JavaFX is on the module path | |
'--add-modules', 'javafx.controls,javafx.fxml' | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment