From 374fc8faa95c4e0c0c35a806408760d088e89762 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Thu, 19 Nov 2020 10:20:35 -0800 Subject: [PATCH] Implemented gradle application plugin --- mpqviewer/build.gradle | 53 ++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/mpqviewer/build.gradle b/mpqviewer/build.gradle index c3362b1a..f7eaf1ce 100644 --- a/mpqviewer/build.gradle +++ b/mpqviewer/build.gradle @@ -1,13 +1,15 @@ apply plugin: 'java' +apply plugin: 'application' -import org.apache.tools.ant.taskdefs.condition.Os +import org.gradle.internal.os.OperatingSystem [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' sourceSets.main.resources.srcDirs += [ file('assets').path ] -project.ext.mainClassName = 'com.riiablo.mpq.MPQViewer' -project.ext.visuiVersion = '1.4.2' +project.ext { + visuiVersion = '1.4.2' +} dependencies { implementation project(':core') @@ -18,24 +20,35 @@ dependencies { implementation "com.kotcrab.vis:vis-ui:$visuiVersion" } -task run(dependsOn: classes, type: JavaExec) { - main = project.mainClassName - classpath = sourceSets.main.runtimeClasspath - standardInput = System.in - workingDir = file('assets').path - ignoreExitValue = true - - if(Os.isFamily(Os.FAMILY_MAC)) - jvmArgs += "-XstartOnFirstThread" +application { + mainClass = 'com.riiablo.mpq.MPQViewer' } -task dist(dependsOn: classes, type: Jar) { - from files(sourceSets.main.output.classesDirs) - from files(sourceSets.main.output.resourcesDir) - from {configurations.compile.collect {zipTree(it)}} - from files(file('assets').path); +run { + workingDir = rootProject.file('assets').path + setIgnoreExitValue(true) - manifest { - attributes 'Main-Class': project.mainClassName - } + // Required to run LWJGL3 java apps on MacOS + if (OperatingSystem.current() == OperatingSystem.MAC_OS) { + jvmArgs += "-XstartOnFirstThread" + } +} + +jar { + archiveBaseName = project.name + // These can be excluded because they add to the jar size but libGDX 1.9.11 can't use them. + // If your libGDX version is 1.9.10 or earlier, or is 1.9.12-SNAPSHOT or later, you can leave + // the following line commented; if you use 1.9.11 exactly, or if you use 1.9.12-SNAPSHOT but + // don't need ARM Linux support, you can uncomment it safely. + // It's always safe to keep that line commented out; it only affects JAR size. + // exclude('linux/arm32/**', 'linux/arm64/**') + dependsOn configurations.runtimeClasspath + from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + manifest { + attributes 'Main-Class': application.mainClass + } + + doLast { + file(archivePath).setExecutable(true, false) + } }