Skip to content

Commit

Permalink
Enable cross-OS compatible fat-jar builds with Gradle's shadowDist ta…
Browse files Browse the repository at this point in the history
…sks.
  • Loading branch information
James authored and James committed Apr 26, 2019
1 parent 8e09e7c commit a17de2f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.15'
compile group: 'com.jfoenix', name: 'jfoenix', version: '9.0.8'

// cross-platform jar: https://github.com/openjfx/samples/blob/master/CommandLine/Non-modular/Gradle/hellofx/build.gradle
// enable these when doing Gradle's shadowDistZip
// for cross-OS compatibility
compile "org.openjfx:javafx-graphics:12.0.1:win"
compile "org.openjfx:javafx-graphics:12.0.1:linux"
compile "org.openjfx:javafx-graphics:12.0.1:mac"
}

compileKotlin {
Expand All @@ -31,4 +38,7 @@ javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}

mainClassName = 'org.idiosapps.MainApp'
application {
mainClassName = 'org.idiosapps.Main'
applicationName = 'gradedReaderBuilder'
}
14 changes: 14 additions & 0 deletions src/main/kotlin/org/idiosapps/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.idiosapps

// https://stackoverflow.com/a/34833438/4261132
// To make a fat jar with JavaFX,
// we can't have the MainClass extend Application
// So, unfortunately we have to hack 2 static methods to get to the app!
class Main {
companion object{
@JvmStatic
fun main(args: Array<String>) {
MainApp.main(args)
}
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/org/idiosapps/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ class MainApp : Application() {
stage.scene = scene
stage.show()
}

companion object{
@JvmStatic
fun main(args: Array<String>) {
launch(MainApp::class.java)
}
}
}

0 comments on commit a17de2f

Please sign in to comment.