build.gradle 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. buildscript {
  2. repositories {
  3. gradlePluginPortal()
  4. }
  5. dependencies {
  6. classpath "io.github.fourlastor:construo:2.1.0"
  7. if(enableGraalNative == 'true') {
  8. classpath "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.9.28"
  9. }
  10. }
  11. }
  12. plugins {
  13. id "application"
  14. }
  15. apply plugin: 'io.github.fourlastor.construo'
  16. import io.github.fourlastor.construo.Target
  17. sourceSets.main.resources.srcDirs += [ rootProject.file('assets').path ]
  18. application.mainClass = 'me.lethunderhawk.lwjgl3.Lwjgl3Launcher'
  19. application.applicationName = appName
  20. eclipse.project.name = appName + '-lwjgl3'
  21. java.sourceCompatibility = 21
  22. java.targetCompatibility = 21
  23. if (JavaVersion.current().isJava9Compatible()) {
  24. compileJava.options.release.set(21)
  25. }
  26. dependencies {
  27. implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
  28. implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
  29. implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
  30. implementation project(':core')
  31. if(enableGraalNative == 'true') {
  32. implementation "io.github.berstanio:gdx-svmhelper-backend-lwjgl3:$graalHelperVersion"
  33. implementation "io.github.berstanio:gdx-svmhelper-extension-box2d:$graalHelperVersion"
  34. }
  35. // Forces LWJGL3 to use at least $lwjgl3Version, currently 3.4.1, to avoid problems on Java 25 and up.
  36. constraints{
  37. implementation("org.lwjgl:lwjgl:$lwjgl3Version")
  38. implementation("org.lwjgl:lwjgl-glfw:$lwjgl3Version")
  39. implementation("org.lwjgl:lwjgl-jemalloc:$lwjgl3Version")
  40. implementation("org.lwjgl:lwjgl-openal:$lwjgl3Version")
  41. implementation("org.lwjgl:lwjgl-opengl:$lwjgl3Version")
  42. implementation("org.lwjgl:lwjgl-stb:$lwjgl3Version")
  43. }
  44. }
  45. def os = System.properties['os.name'].toLowerCase(Locale.ROOT)
  46. run {
  47. workingDir = rootProject.file('assets').path
  48. // You can uncomment the next line if your IDE claims a build failure even when the app closed properly.
  49. //setIgnoreExitValue(true)
  50. jvmArgs += "--enable-native-access=ALL-UNNAMED"
  51. if (os.contains('mac')) jvmArgs += "-XstartOnFirstThread"
  52. }
  53. jar {
  54. // sets the name of the .jar file this produces to the name of the game or app, with the version after.
  55. archiveFileName.set("${appName}-${projectVersion}.jar")
  56. // the duplicatesStrategy matters starting in Gradle 7.0; this setting works.
  57. duplicatesStrategy = DuplicatesStrategy.EXCLUDE
  58. dependsOn configurations.runtimeClasspath
  59. from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
  60. // these "exclude" lines remove some unnecessary duplicate files in the output JAR.
  61. exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
  62. dependencies {
  63. exclude('META-INF/INDEX.LIST', 'META-INF/maven/**')
  64. }
  65. // setting the manifest makes the JAR runnable.
  66. // enabling native access helps avoid a warning when Java 24 or later runs the JAR.
  67. // setting Multi-Release to true allows LWJGL3 to use different classes on recent Java versions.
  68. manifest {
  69. attributes 'Main-Class': application.mainClass, 'Enable-Native-Access': 'ALL-UNNAMED', 'Multi-Release': 'true'
  70. }
  71. // this last step may help on some OSes that need extra instruction to make runnable JARs.
  72. doLast {
  73. file(archiveFile).setExecutable(true, false)
  74. }
  75. }
  76. // Builds a JAR that only includes the files needed to run on macOS, not Windows or Linux.
  77. // The file size for a Mac-only JAR is about 7MB smaller than a cross-platform JAR.
  78. tasks.register("jarMac") {
  79. dependsOn("jar")
  80. group("build")
  81. jar.archiveFileName.set("${appName}-${projectVersion}-mac.jar")
  82. jar.exclude("windows/x86/**", "windows/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**", "**/*.dll", "**/*.so",
  83. 'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
  84. dependencies {
  85. jar.exclude("windows/x86/**", "windows/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**",
  86. 'META-INF/INDEX.LIST', 'META-INF/maven/**')
  87. }
  88. }
  89. // Builds a JAR that only includes the files needed to run on Linux, not Windows or macOS.
  90. // The file size for a Linux-only JAR is about 5MB smaller than a cross-platform JAR.
  91. tasks.register("jarLinux") {
  92. dependsOn("jar")
  93. group("build")
  94. jar.archiveFileName.set("${appName}-${projectVersion}-linux.jar")
  95. jar.exclude("windows/x86/**", "windows/x64/**", "macos/arm64/**", "macos/x64/**", "**/*.dll", "**/*.dylib",
  96. 'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
  97. dependencies {
  98. jar.exclude("windows/x86/**", "windows/x64/**", "macos/arm64/**", "macos/x64/**",
  99. 'META-INF/INDEX.LIST', 'META-INF/maven/**')
  100. }
  101. }
  102. // Builds a JAR that only includes the files needed to run on Windows, not Linux or macOS.
  103. // The file size for a Windows-only JAR is about 6MB smaller than a cross-platform JAR.
  104. tasks.register("jarWin") {
  105. dependsOn("jar")
  106. group("build")
  107. jar.archiveFileName.set("${appName}-${projectVersion}-win.jar")
  108. jar.exclude("macos/arm64/**", "macos/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**", "**/*.dylib", "**/*.so",
  109. 'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
  110. dependencies {
  111. jar.exclude("macos/arm64/**", "macos/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**",
  112. 'META-INF/INDEX.LIST', 'META-INF/maven/**')
  113. }
  114. }
  115. construo {
  116. // name of the executable
  117. name.set(appName)
  118. // human-readable name, used for example in the `.app` name for macOS
  119. humanName.set(appName)
  120. jlink {
  121. guessModulesFromJar.set(false)
  122. // You may need to add more modules, as needed.
  123. modules.addAll("java.base", "java.management", "java.desktop", "jdk.unsupported")
  124. }
  125. targets.configure {
  126. register("linuxX64", Target.Linux) {
  127. architecture.set(Target.Architecture.X86_64)
  128. jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_x64_linux_hotspot_21.0.10_7.tar.gz")
  129. // Linux does not currently have a way to set the icon on the executable
  130. }
  131. register("macM1", Target.MacOs) {
  132. architecture.set(Target.Architecture.AARCH64)
  133. jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_aarch64_mac_hotspot_21.0.10_7.tar.gz")
  134. // macOS needs an identifier
  135. identifier.set("me.lethunderhawk." + appName)
  136. // Optional: icon for macOS, as an ICNS file
  137. macIcon.set(project.file("icons/logo.icns"))
  138. }
  139. register("macX64", Target.MacOs) {
  140. architecture.set(Target.Architecture.X86_64)
  141. jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_x64_mac_hotspot_21.0.10_7.tar.gz")
  142. // macOS needs an identifier
  143. identifier.set("me.lethunderhawk." + appName)
  144. // Optional: icon for macOS, as an ICNS file
  145. macIcon.set(project.file("icons/logo.icns"))
  146. }
  147. register("winX64", Target.Windows) {
  148. architecture.set(Target.Architecture.X86_64)
  149. // Optional: icon for Windows, as a PNG
  150. icon.set(project.file("icons/logo.png"))
  151. jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_x64_windows_hotspot_21.0.10_7.zip")
  152. // Uncomment the next line to show a console when the game runs, to print messages.
  153. //useConsole.set(true)
  154. }
  155. }
  156. }
  157. // Equivalent to the jar task; here for compatibility with gdx-setup.
  158. tasks.register('dist') {
  159. dependsOn 'jar'
  160. }
  161. distributions {
  162. main {
  163. contents {
  164. into('libs') {
  165. project.configurations.runtimeClasspath.files.findAll { file ->
  166. file.getName() != project.tasks.jar.outputs.files.singleFile.name
  167. }.each { file ->
  168. exclude file.name
  169. }
  170. }
  171. }
  172. }
  173. }
  174. startScripts.dependsOn(':lwjgl3:jar')
  175. startScripts.classpath = project.tasks.jar.outputs.files
  176. // Helps if debugging on Linux with an Nvidia GPU.
  177. // This means StartupHelper won't try to restart the JVM, which can prevent debugging.
  178. // This only applies to Gradle tasks, not main methods debugged when launching a main() method directly.
  179. // As a more general solution, set the environment variable __GL_THREADED_OPTIMIZATIONS to 0 globally, on Linux
  180. // machines with Nvidia GPUs where you need to debug LWJGL3 apps and games.
  181. // You can also set __GL_THREADED_OPTIMIZATIONS to 0 in run configurations, which you would need per main() method.
  182. // StartupHelper will still restart the JVM to set this environment variable when run as a distributable JAR, which is
  183. // a good thing for end users. They won't need to ever set the debug-specific environment variable.
  184. tasks.withType(JavaExec.class).configureEach {
  185. environment("__GL_THREADED_OPTIMIZATIONS", 0)
  186. }
  187. if(enableGraalNative == 'true') {
  188. apply from: file("nativeimage.gradle")
  189. }