Skip to content

Instantly share code, notes, and snippets.

@fathonyfath
Created September 8, 2019 08:48
Show Gist options
  • Save fathonyfath/e4009d8e7ba5be5d184f619a3806b307 to your computer and use it in GitHub Desktop.
Save fathonyfath/e4009d8e7ba5be5d184f619a3806b307 to your computer and use it in GitHub Desktop.
Snippets that you can use to deploy stand-alone Java application
def mainClassName = 'sample.app.AppKt'
def embeddedJRE = true
jar {
manifest {
attributes(
'Main-Class': mainClassName,
'Class-Path': configurations.default.collect { it.getName() }.join(' ')
)
}
}
task copyDependencies(type: Copy) {
from configurations.default
into "$buildDir/$libsDirName"
}
task javapackager(type: Exec, dependsOn: [assemble, copyDependencies]) {
def nativeType
if (System.getProperty("os.name").toLowerCase().contains('windows'))
nativeType = ['msi']
else if (System.getProperty("os.name").toLowerCase().contains('mac'))
nativeType = ['dmg']
else if (System.getProperty("os.name").toLowerCase().contains('linux'))
nativeType = ['rpm']
else
nativeType = []
def dependencies = []
configurations.default.forEach({ file ->
dependencies.add('-srcfiles')
dependencies.add(file.getName())
})
def paramEmbeddedJRE = embeddedJRE ? [] : ['-Bruntime=']
workingDir project.projectDir
commandLine = [
'javapackager',
'-deploy',
'-nosign',
'-outdir', "${buildDir}/distribution",
'-outfile', project.name,
'-name', 'Application Seed',
'-appclass', mainClassName,
'-srcdir', "$buildDir/$libsDirName",
'-srcfiles', jar.archiveFileName.get()
] + dependencies + paramEmbeddedJRE + ['-native'] + nativeType
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment