Skip to content

Instantly share code, notes, and snippets.

@SManAT
Last active May 25, 2021 06:14
Show Gist options
  • Save SManAT/9bb2ffae07adb466bc8aad1241c41261 to your computer and use it in GitHub Desktop.
Save SManAT/9bb2ffae07adb466bc8aad1241c41261 to your computer and use it in GitHub Desktop.
To build a Project with all dependencies and bundled JRE on Windows
plugins {
id 'java'
id 'jacoco'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
id 'org.beryx.runtime' version '1.12.5'
id "edu.sc.seis.launch4j" version "2.5.0"
}
/* Variables ---------------------------------------------------------------- */
sourceCompatibility = 1.8
targetCompatibility = 1.11
mainClassName = 'SH.TrayNotifications.Test.Main'
/* where to assemble the project */
def outputDir='dist/'
/* End Variables */
/* Zip/Tar Distribution? */
distZip.enabled = false
distTar.enabled = false
/* Create a Starter in order to run the JAR File direct, otherwise there are
* missing JavaFX Runtime Components
*/
javafx {
version = "16"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
/* Tasks ---------------------------------------------------------------- */
task copyJRE(type: Copy) {
into "build/$outputDir"
/* JRE Runtime */
from("/build/jre") {
into 'jre'
}
}
tasks.runtime.finalizedBy(copyJRE)
launch4j {
mainClassName = mainClassName
/* important because my Jar is not in dir lib/... */
icon = "${projectDir}/src/main/resources/App.ico"
/* Use JRE INSIDE this Directoty */
bundledJrePath = "jre"
bundledJre64Bit = true
language = "GERMAN"
//headerType = 'console'
dontWrapJar = true
}
task copyExe(type: Copy) {
into "build/$outputDir"
/* Resourcen */
from('/build/launch4j') {
include "*.exe"
}
}
/* finally copy created EXE File to output Dir */
createExe.finalizedBy(copyExe)
/* -------------------------------------------------------------------------- */
repositories{
mavenCentral()
}
dependencies {
testImplementation 'junit:junit:4.12'
//--------------------------------------------------------------------------
/* Locale Projects, see also settings.gradle */
implementation project(':TrayNotification')
}
/* Create the JAR File with dependencies in subdir lib/ --------------------- */
/* Write the correct Manifest ----------------------------------------------- */
configurations.implementation.setCanBeResolved(true)
jar {
from "$buildDir/libs/lib"
manifest {
attributes 'Main-Class': mainClassName,
'Class-Path': configurations.runtimeClasspath.collect { 'lib/'+it.getName() }.join(' ')
}
}
task copyToLib(type: Copy) {
into "$buildDir/libs/lib"
from configurations.implementation
}
build.dependsOn(copyToLib)
/* Copy it all together ----------------------------------------------------- */
task copyStuff(type: Copy) {
into "build/$outputDir"
/* Resourcen */
from('/') {
include "*.*"
exclude 'launch4j.*', '*.gradle', '*.properties', '*.bat', '*.txt', '*.log', '*.sql', 'config_home.xml', 'config_schule.xml'
}
from("/scripts") {
into 'scripts'
}
/* JAR File */
from("/build/libs/") {}
}
task moveJAR(type: Copy) {
into "build/$outputDir/lib"
from("/build/libs/") {
include "*.jar"
}
}
build.finalizedBy(copyStuff)
tasks.copyStuff.finalizedBy(moveJAR)
/* my own tasks ------------------------------------------------------------- */
task deleteDirs(type: Delete) {
delete "/build/launch4j/", "/build/jre/", "/build/libs/"
followSymlinks = true
}
task all(dependsOn: ['clean', 'build', 'runtime']){
description = 'Clean, build and bundle for OS'
}
build.mustRunAfter clean
tasks.runtime.finalizedBy(createExe)
tasks.createExe.finalizedBy(deleteDirs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment