149 lines
5.4 KiB
Groovy
149 lines
5.4 KiB
Groovy
buildscript {
|
|
}
|
|
plugins {
|
|
id "application"
|
|
}
|
|
apply plugin: 'java-library'
|
|
|
|
// From https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/
|
|
// The article can be helpful when using assets.txt in your project.
|
|
tasks.register('generateAssetList') {
|
|
inputs.dir("${project.rootDir}/assets/")
|
|
// projectFolder/assets
|
|
File assetsFolder = new File("${project.rootDir}/assets/")
|
|
// projectFolder/assets/assets.txt
|
|
File assetsFile = new File(assetsFolder, "assets.txt")
|
|
// delete that file in case we've already created it
|
|
assetsFile.delete()
|
|
|
|
// iterate through all files inside that folder
|
|
// convert it to a relative path
|
|
// and append it to the file assets.txt
|
|
fileTree(assetsFolder).collect { assetsFolder.relativePath(it) }.sort().each {
|
|
assetsFile.append(it + "\n")
|
|
}
|
|
}
|
|
processResources.dependsOn 'generateAssetList'
|
|
|
|
compileJava {
|
|
options.incremental = true
|
|
}
|
|
|
|
version = "$projectVersion"
|
|
ext.appName = 'Labyrinth'
|
|
repositories {
|
|
mavenCentral()
|
|
// You may want to remove the following line if you have errors downloading dependencies.
|
|
mavenLocal()
|
|
maven { url = 'https://central.sonatype.com/repository/maven-snapshots/' }
|
|
maven { url = 'https://jitpack.io' }
|
|
}
|
|
|
|
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
|
|
|
sourceSets.main.resources.srcDirs += [ rootProject.file('assets').path ]
|
|
application.mainClass = 'net.caraus.labyrinth.lwjgl3.Lwjgl3Launcher'
|
|
|
|
java.sourceCompatibility = 17
|
|
java.targetCompatibility = 21
|
|
if (JavaVersion.current().isJava9Compatible()) {
|
|
compileJava.options.release.set(17)
|
|
}
|
|
|
|
dependencies {
|
|
api "com.badlogicgames.gdx:gdx:$gdxVersion"
|
|
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
|
|
implementation "com.badlogicgames.gdx:gdx-lwjgl3-angle:$gdxVersion"
|
|
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
|
}
|
|
|
|
def os = System.properties['os.name'].toLowerCase(Locale.ROOT)
|
|
|
|
run {
|
|
workingDir = rootProject.file('assets').path
|
|
|
|
if (os.contains('mac')) jvmArgs += "-XstartOnFirstThread"
|
|
}
|
|
|
|
jar {
|
|
// sets the name of the .jar file this produces to the name of the game or app, with the version after.
|
|
archiveFileName.set("${appName}-${projectVersion}.jar")
|
|
// the duplicatesStrategy matters starting in Gradle 7.0; this setting works.
|
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
dependsOn configurations.runtimeClasspath
|
|
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
|
// these "exclude" lines remove some unnecessary duplicate files in the output JAR.
|
|
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
|
|
dependencies {
|
|
exclude('META-INF/INDEX.LIST', 'META-INF/maven/**')
|
|
}
|
|
// setting the manifest makes the JAR runnable.
|
|
// enabling native access helps avoid a warning when Java 24 or later runs the JAR.
|
|
manifest {
|
|
attributes 'Main-Class': application.mainClass, 'Enable-Native-Access': 'ALL-UNNAMED'
|
|
}
|
|
// this last step may help on some OSes that need extra instruction to make runnable JARs.
|
|
doLast {
|
|
file(archiveFile).setExecutable(true, false)
|
|
}
|
|
}
|
|
|
|
// Builds a JAR that only includes the files needed to run on macOS, not Windows or Linux.
|
|
// The file size for a Mac-only JAR is about 7MB smaller than a cross-platform JAR.
|
|
tasks.register("jarMac") {
|
|
dependsOn("jar")
|
|
group("build")
|
|
jar.archiveFileName.set("${appName}-${projectVersion}-mac.jar")
|
|
jar.exclude("windows/x86/**", "windows/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**", "**/*.dll", "**/*.so",
|
|
'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
|
|
dependencies {
|
|
jar.exclude("windows/x86/**", "windows/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**",
|
|
'META-INF/INDEX.LIST', 'META-INF/maven/**')
|
|
}
|
|
}
|
|
|
|
// Builds a JAR that only includes the files needed to run on Linux, not Windows or macOS.
|
|
// The file size for a Linux-only JAR is about 5MB smaller than a cross-platform JAR.
|
|
tasks.register("jarLinux") {
|
|
dependsOn("jar")
|
|
group("build")
|
|
jar.archiveFileName.set("${appName}-${projectVersion}-linux.jar")
|
|
jar.exclude("windows/x86/**", "windows/x64/**", "macos/arm64/**", "macos/x64/**", "**/*.dll", "**/*.dylib",
|
|
'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
|
|
dependencies {
|
|
jar.exclude("windows/x86/**", "windows/x64/**", "macos/arm64/**", "macos/x64/**",
|
|
'META-INF/INDEX.LIST', 'META-INF/maven/**')
|
|
}
|
|
}
|
|
|
|
// Builds a JAR that only includes the files needed to run on Windows, not Linux or macOS.
|
|
// The file size for a Windows-only JAR is about 6MB smaller than a cross-platform JAR.
|
|
tasks.register("jarWin") {
|
|
dependsOn("jar")
|
|
group("build")
|
|
jar.archiveFileName.set("${appName}-${projectVersion}-win.jar")
|
|
jar.exclude("macos/arm64/**", "macos/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**", "**/*.dylib", "**/*.so",
|
|
'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
|
|
dependencies {
|
|
jar.exclude("macos/arm64/**", "macos/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**",
|
|
'META-INF/INDEX.LIST', 'META-INF/maven/**')
|
|
}
|
|
}
|
|
|
|
distributions {
|
|
main {
|
|
contents {
|
|
into('libs') {
|
|
project.configurations.runtimeClasspath.files.findAll { file ->
|
|
file.getName() != project.tasks.jar.outputs.files.singleFile.name
|
|
}.each { file ->
|
|
exclude file.name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
startScripts.dependsOn(':lwjgl3:jar')
|
|
startScripts.classpath = project.tasks.jar.outputs.files
|