Last active
March 14, 2022 11:36
-
-
Save falkoschumann/6c0abf0f9f65a02babad6b070dcf4598 to your computer and use it in GitHub Desktop.
javapackager with Gradle
This file contains 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
group 'de.muspellheim' | |
version '1.0.0' | |
apply plugin: 'java' | |
sourceCompatibility = 1.8 | |
compileJava.options.encoding = 'UTF-8' | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
compile 'org.postgresql:postgresql:42.1.4' | |
testCompile 'junit:junit:4.+' | |
} | |
def mainClassName = 'de.muspellheim.application.App' | |
def embeddedJRE = false | |
jar { | |
manifest { | |
attributes( | |
'Main-Class': mainClassName, | |
'Class-Path': configurations.runtime.collect { it.getName() }.join(' ') | |
) | |
} | |
} | |
task copyDependencies(type: Copy) { | |
destinationDir libsDir | |
from configurations.runtime | |
} | |
task javapackager(type: Exec, dependsOn: [assemble, copyDependencies]) { | |
def nativeType | |
if (System.properties['os.name'].toLowerCase().contains('windows')) | |
nativeType = 'msi' | |
if (System.properties['os.name'].toLowerCase().contains('mac')) | |
nativeType = 'dmg' | |
if (System.properties['os.name'].toLowerCase().contains('linux')) | |
nativeType = 'rpm' | |
def dependencies = [] | |
configurations.runtime.forEach({ file -> | |
dependencies.add('-srcfiles') | |
dependencies.add(file.getName()) | |
}) | |
def paramEmbeddedJRE = embeddedJRE ? [] : ['-Bruntime='] | |
workingDir project.projectDir | |
commandLine = [ | |
'javapackager', | |
'-deploy', | |
'-nosign', | |
'-native', nativeType, | |
'-outdir', "${buildDir}/distribution", | |
'-outfile', project.name, | |
'-name', 'Application Seed', | |
'-appclass', mainClassName, | |
'-srcdir', libsDir, | |
'-srcfiles', jar.archiveName | |
] + dependencies + paramEmbeddedJRE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're a champ - thank you for this.