Skip to content

Instantly share code, notes, and snippets.

@falkoschumann
Last active March 14, 2022 11:36
Show Gist options
  • Save falkoschumann/6c0abf0f9f65a02babad6b070dcf4598 to your computer and use it in GitHub Desktop.
Save falkoschumann/6c0abf0f9f65a02babad6b070dcf4598 to your computer and use it in GitHub Desktop.
javapackager with Gradle
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
}
@jezhiggins
Copy link

You're a champ - thank you for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment