feat: add ability to build a cross-platform jar

This commit is contained in:
Arnaud Vergnet 2020-11-23 16:07:09 +01:00
parent f0006ad764
commit f94b78948e
4 changed files with 48 additions and 8 deletions

View file

@ -28,7 +28,7 @@ Follow [this link](https://gluonhq.com/products/scene-builder/) to download and
#### Build and Run #### Build and Run
Run this command Run this command
```shell script ```shell script
./gradlew run ./gradlew run
@ -36,6 +36,24 @@ Run this command
Or in Intellij, open the gradle window and click on `clavardator -> Tasks -> application -> run`. Or in Intellij, open the gradle window and click on `clavardator -> Tasks -> application -> run`.
#### Generate cross-platform jar
Run this command
```shell script
./gradlew build
```
This will generate a jar file under `build/libs`.
You can then copy this file and place it on any Linux/Windows/Mac environment with at least Java 11 installed.
You can then run this jar file with this command:
```shell script
java -jar <JAR-NAME>.jar
```
## Resources ## Resources
* [OpenJDK](https://adoptopenjdk.net/releases.html) * [OpenJDK](https://adoptopenjdk.net/releases.html)

View file

@ -4,25 +4,38 @@ plugins {
} }
group 'fr.insa.clavardator' group 'fr.insa.clavardator'
version '1.0-SNAPSHOT' version '0.0.1'
repositories { repositories {
mavenCentral() mavenCentral()
} }
dependencies {
implementation 'org.xerial:sqlite-jdbc:3.32.3'
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
}
javafx { javafx {
version = "11.0.2" version = "11.0.2"
modules = [ 'javafx.controls', 'javafx.fxml' ] modules = [ 'javafx.controls', 'javafx.fxml' ]
} }
dependencies {
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:win"
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:linux"
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:mac"
implementation 'org.xerial:sqlite-jdbc:3.32.3'
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
}
test { test {
useJUnitPlatform() useJUnitPlatform()
} }
jar {
manifest {
attributes 'Main-Class': 'fr.insa.clavardator.Launcher'
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
mainClassName = 'fr.insa.clavardator.MainApp' mainClassName = 'fr.insa.clavardator.MainApp'

View file

@ -0,0 +1,7 @@
package fr.insa.clavardator;
public class Launcher {
public static void main(String[] args) {
MainApp.main(args);
}
}

View file

@ -1,3 +1,5 @@
package fr.insa.clavardator;
import fr.insa.clavardator.TestClass; import fr.insa.clavardator.TestClass;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;