Advertisement
tedigc

raeleus is bae

May 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. apply plugin: "java"
  2.  
  3. sourceCompatibility = 1.8
  4. sourceSets.main.java.srcDirs = [ "src/" ]
  5.  
  6. project.ext.mainClassName = "com.halfcut.galaxygarden.desktop.DesktopLauncher"
  7. project.ext.assetsDir = new File("../core/assets")
  8. def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)
  9.  
  10. task run(dependsOn: classes, type: JavaExec) {
  11. main = project.mainClassName
  12. classpath = sourceSets.main.runtimeClasspath
  13. standardInput = System.in
  14. workingDir = project.assetsDir
  15. ignoreExitValue = true
  16. }
  17.  
  18. task debug(dependsOn: classes, type: JavaExec) {
  19. main = project.mainClassName
  20. classpath = sourceSets.main.runtimeClasspath
  21. standardInput = System.in
  22. workingDir = project.assetsDir
  23. ignoreExitValue = true
  24. debug = true
  25. }
  26.  
  27. task dist(type: Jar) {
  28. baseName = "galaxy-garden"
  29. from files(sourceSets.main.output.classesDir)
  30. from files(sourceSets.main.output.resourcesDir)
  31. from {configurations.compile.collect {zipTree(it)}}
  32. from files(project.assetsDir)
  33. manifest {
  34. attributes 'Main-Class': project.mainClassName
  35. }
  36. }
  37.  
  38. dist.dependsOn classes
  39.  
  40. eclipse {
  41. project {
  42. name = appName + "-desktop"
  43. linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
  44. }
  45. }
  46.  
  47. task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
  48. doLast {
  49. def classpath = new XmlParser().parse(file(".classpath"))
  50. new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
  51. def writer = new FileWriter(file(".classpath"))
  52. def printer = new XmlNodePrinter(new PrintWriter(writer))
  53. printer.setPreserveWhitespace(true)
  54. printer.print(classpath)
  55. }
  56. }
  57.  
  58. // creates application bundle (executable + runtime)
  59. task jpackageStart(type: Exec, dependsOn: dist) {
  60. workingDir project.projectDir
  61. def commands = [
  62. "${project.projectDir}/jpackage/bin/jpackage",
  63. 'create-image',
  64. '--output', "${buildDir}/distribution",
  65. '--input', "${buildDir}/libs",
  66. '--name', project.appName,
  67. '--main-class', project.mainClassName,
  68. '--main-jar', "${project.appName}.jar",
  69. '--overwrite'
  70. ]
  71.  
  72. if (osName.contains('windows')) {
  73. // commands << '--icon'
  74. // commands << "${project.projectDir}/logo.ico"
  75. commands << '--jvm-args'
  76. commands << "-splash:splash.png"
  77. } else if (osName.contains('linux')) {
  78. // commands << '--icon'
  79. // commands << "${project.projectDir}/logo.png"
  80. commands << '--jvm-args'
  81. commands << "-splash:splash.png"
  82. } else if (osName.contains('mac')) {
  83. // commands << '--icon'
  84. // commands << "${project.projectDir}/logo.icns"
  85. commands << '--jvm-args'
  86. commands << "-XstartOnFirstThread"
  87. }
  88.  
  89. commandLine = commands
  90.  
  91. doLast() {
  92. if (!osName.contains('mac')) {
  93. copy {
  94. from '../core/assets/splash.png'
  95. into "${buildDir}/distribution/${project.appName}/app"
  96. }
  97. }
  98. }
  99. }
  100.  
  101. // removes bloated runtime created by javapackager
  102. task jpackageCleanRuntime(dependsOn: jpackageStart) {
  103. doLast() {
  104. File runtimeFile = new File("${buildDir}/distribution/${project.appName}/runtime")
  105. if (osName.contains('mac')) {
  106. runtimeFile = new File("${buildDir}/distribution/${project.appName}.app/contents/plugins/Java.runtime/Contents/Home")
  107. }
  108. runtimeFile.deleteDir()
  109. delete {
  110. delete fileTree("${buildDir}/distribution/${project.appName}").matching {
  111. include "api*.dll"
  112. }
  113. }
  114. System.out.println("deleting bloated runtime in " + runtimeFile)
  115. }
  116. }
  117.  
  118. // creates a replacement runtime via jlink command (much smaller than jpackager)
  119. task jpackageAppBundle(type: Exec, dependsOn: [jpackageCleanRuntime]) {
  120. String runtimePath = "${buildDir}/distribution/${project.appName}/runtime"
  121. if (osName.contains('mac')) {
  122. runtimePath = "${buildDir}/distribution/${project.appName}.app/contents/plugins/Java.runtime/Contents/Home"
  123. }
  124.  
  125. workingDir project.projectDir
  126. commandLine = [
  127. "${project.projectDir}/jpackage/bin/jlink",
  128. '-p', "${project.projectDir}/jpackage/jmods",
  129. '--add-modules', 'java.base,java.desktop,jdk.unsupported',
  130. '--strip-debug',
  131. '--no-header-files',
  132. '--no-man-pages',
  133. '--strip-native-commands',
  134. "--vm=server",
  135. "--compress=2",
  136. '--output', runtimePath
  137. ]
  138.  
  139. doLast{
  140. System.out.println("Application '${project.appName}' packaged.")
  141. System.out.println(" -> location: ${buildDir}/distribution/${project.appName}/")
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement