Created
September 8, 2019 08:48
-
-
Save fathonyfath/e4009d8e7ba5be5d184f619a3806b307 to your computer and use it in GitHub Desktop.
Snippets that you can use to deploy stand-alone Java application
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
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