Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- apply plugin: "java"
- sourceCompatibility = 1.8
- sourceSets.main.java.srcDirs = [ "src/" ]
- project.ext.mainClassName = "com.halfcut.galaxygarden.desktop.DesktopLauncher"
- project.ext.assetsDir = new File("../core/assets")
- def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)
- task run(dependsOn: classes, type: JavaExec) {
- main = project.mainClassName
- classpath = sourceSets.main.runtimeClasspath
- standardInput = System.in
- workingDir = project.assetsDir
- ignoreExitValue = true
- }
- task debug(dependsOn: classes, type: JavaExec) {
- main = project.mainClassName
- classpath = sourceSets.main.runtimeClasspath
- standardInput = System.in
- workingDir = project.assetsDir
- ignoreExitValue = true
- debug = true
- }
- task dist(type: Jar) {
- baseName = "galaxy-garden"
- from files(sourceSets.main.output.classesDir)
- from files(sourceSets.main.output.resourcesDir)
- from {configurations.compile.collect {zipTree(it)}}
- from files(project.assetsDir)
- manifest {
- attributes 'Main-Class': project.mainClassName
- }
- }
- dist.dependsOn classes
- eclipse {
- project {
- name = appName + "-desktop"
- linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
- }
- }
- task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
- doLast {
- def classpath = new XmlParser().parse(file(".classpath"))
- new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
- def writer = new FileWriter(file(".classpath"))
- def printer = new XmlNodePrinter(new PrintWriter(writer))
- printer.setPreserveWhitespace(true)
- printer.print(classpath)
- }
- }
- // creates application bundle (executable + runtime)
- task jpackageStart(type: Exec, dependsOn: dist) {
- workingDir project.projectDir
- def commands = [
- "${project.projectDir}/jpackage/bin/jpackage",
- 'create-image',
- '--output', "${buildDir}/distribution",
- '--input', "${buildDir}/libs",
- '--name', project.appName,
- '--main-class', project.mainClassName,
- '--main-jar', "${project.appName}.jar",
- '--overwrite'
- ]
- if (osName.contains('windows')) {
- // commands << '--icon'
- // commands << "${project.projectDir}/logo.ico"
- commands << '--jvm-args'
- commands << "-splash:splash.png"
- } else if (osName.contains('linux')) {
- // commands << '--icon'
- // commands << "${project.projectDir}/logo.png"
- commands << '--jvm-args'
- commands << "-splash:splash.png"
- } else if (osName.contains('mac')) {
- // commands << '--icon'
- // commands << "${project.projectDir}/logo.icns"
- commands << '--jvm-args'
- commands << "-XstartOnFirstThread"
- }
- commandLine = commands
- doLast() {
- if (!osName.contains('mac')) {
- copy {
- from '../core/assets/splash.png'
- into "${buildDir}/distribution/${project.appName}/app"
- }
- }
- }
- }
- // removes bloated runtime created by javapackager
- task jpackageCleanRuntime(dependsOn: jpackageStart) {
- doLast() {
- File runtimeFile = new File("${buildDir}/distribution/${project.appName}/runtime")
- if (osName.contains('mac')) {
- runtimeFile = new File("${buildDir}/distribution/${project.appName}.app/contents/plugins/Java.runtime/Contents/Home")
- }
- runtimeFile.deleteDir()
- delete {
- delete fileTree("${buildDir}/distribution/${project.appName}").matching {
- include "api*.dll"
- }
- }
- System.out.println("deleting bloated runtime in " + runtimeFile)
- }
- }
- // creates a replacement runtime via jlink command (much smaller than jpackager)
- task jpackageAppBundle(type: Exec, dependsOn: [jpackageCleanRuntime]) {
- String runtimePath = "${buildDir}/distribution/${project.appName}/runtime"
- if (osName.contains('mac')) {
- runtimePath = "${buildDir}/distribution/${project.appName}.app/contents/plugins/Java.runtime/Contents/Home"
- }
- workingDir project.projectDir
- commandLine = [
- "${project.projectDir}/jpackage/bin/jlink",
- '-p', "${project.projectDir}/jpackage/jmods",
- '--add-modules', 'java.base,java.desktop,jdk.unsupported',
- '--strip-debug',
- '--no-header-files',
- '--no-man-pages',
- '--strip-native-commands',
- "--vm=server",
- "--compress=2",
- '--output', runtimePath
- ]
- doLast{
- System.out.println("Application '${project.appName}' packaged.")
- System.out.println(" -> location: ${buildDir}/distribution/${project.appName}/")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement