Mindustry/desktop/build.gradle

214 lines
7.4 KiB
Groovy
Raw Normal View History

2021-06-05 19:57:25 +07:00
sourceSets.main.java.srcDirs = ["src/"]
2017-04-30 08:25:59 +07:00
2019-12-25 13:39:38 +07:00
project.ext.mainClassName = "mindustry.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../core/assets")
2019-08-25 05:29:21 +07:00
def enableTemplates = true
2019-09-22 03:44:47 +07:00
def JDK_DIR = "$System.env.JDK_DIR"
2020-09-16 06:28:38 +07:00
def ICON_DIR = new File("$rootDir/core/assets/icons/icon.icns")
2021-06-05 07:19:11 +07:00
def platforms = ["Linux64", "Windows64", "Windows32", "MacOS"]
2017-04-30 08:25:59 +07:00
task run(dependsOn: classes, type: JavaExec){
mainClass = project.mainClassName
2017-04-30 08:25:59 +07:00
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
if(System.getProperty("os.name").toLowerCase().contains("mac")){
2021-06-02 22:08:08 +07:00
jvmArgs("-XstartOnFirstThread")
}
jvmArgs += "-XX:+ShowCodeDetailsInExceptionMessages"
if(project.hasProperty("args")){
2018-09-11 06:33:12 +07:00
args Eval.me(project.getProperties()["args"])
}
if(project.hasProperty("jvmArgs")){
jvmArgs((List<String>)Eval.me(project.getProperties()["jvmArgs"]))
}
2022-10-18 23:56:07 +07:00
if(project.hasProperty("dataDir")){
environment("MINDUSTRY_DATA_DIR", project.getProperties()["dataDir"])
}
2018-09-11 06:33:12 +07:00
if(args.contains("debug")){
mainClass = "mindustry.debug.DebugLauncher"
2017-12-22 08:59:40 +07:00
}
2017-04-30 08:25:59 +07:00
}
task dist(type: Jar, dependsOn: configurations.runtimeClasspath){
2023-09-04 08:15:50 +07:00
dependsOn ":desktop:processResources"
2018-02-02 10:16:00 +07:00
from files(sourceSets.main.output.classesDirs)
2017-04-30 08:25:59 +07:00
from files(sourceSets.main.output.resourcesDir)
2020-05-15 09:00:04 +07:00
from {configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it) }}
from files(project.assetsDir)
2021-06-02 22:08:08 +07:00
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
//don't include steam shared libraries unless necessary
if(!versionModifier.contains("steam")){
exclude("**steam**.so", "**steam**.dll", "**steam**.dylib")
}
2019-11-16 07:48:26 +07:00
archiveFileName = "${appName}.jar"
manifest{
2017-04-30 08:25:59 +07:00
attributes 'Main-Class': project.mainClassName
}
}
2021-06-14 22:15:06 +07:00
if(!project.ext.hasSprites() && System.getenv("JITPACK") != "true"){
2020-12-17 22:15:58 +07:00
println "Scheduling sprite packing."
2020-12-16 03:24:09 +07:00
run.dependsOn ":tools:pack"
dist.dependsOn ":tools:pack"
}
2021-06-02 22:08:08 +07:00
//this is only for local testing
2022-04-17 22:08:51 +07:00
//add -Prelease -PversionModifier=steam as build properties
2019-08-22 20:27:59 +07:00
task steamtest(dependsOn: dist){
doLast{
2019-08-22 07:10:54 +07:00
copy{
2019-08-23 03:13:39 +07:00
from "build/libs/Mindustry.jar"
2023-12-06 01:57:41 +07:00
if(project.hasProperty("destination")){
into project.property("destination")
}else if(System.properties["os.name"].contains("Mac")){
2019-09-16 00:52:56 +07:00
into "/Users/anuke/Library/Application Support/Steam/steamapps/common/Mindustry/Mindustry.app/Contents/Resources"
2019-08-23 03:13:39 +07:00
}else{
2019-08-23 03:44:32 +07:00
into "/home/anuke/.steam/steam/steamapps/common/Mindustry/jre"
2019-08-23 03:13:39 +07:00
}
2019-08-23 03:19:29 +07:00
rename("Mindustry.jar", "desktop.jar")
}
}
}
2021-06-05 04:32:53 +07:00
//required templates:
2021-06-05 19:57:25 +07:00
//- Windows32: Not provided by Packr! This uses Java 8
2021-06-05 04:32:53 +07:00
//required JDKs:
2021-06-05 19:57:25 +07:00
//- Windows64
2021-06-05 04:32:53 +07:00
//- Linux64
//- Mac
2021-06-05 07:19:11 +07:00
platforms.each{ platform ->
2019-08-22 01:46:36 +07:00
task "packr${platform.toString()}"{
dependsOn dist
doLast{
copy{
into "build/packr/"
rename("${appName}.jar", "desktop.jar")
from "build/libs/${appName}.jar"
}
delete{
delete "build/packr/output/"
}
2021-06-05 07:19:11 +07:00
//the Windows32 version uses an old java-8 based template, because packr and jpackage don't support win32
if(enableTemplates && (platform == "Windows32")){
2019-08-22 01:46:36 +07:00
copy{
into "build/packr/output"
2019-08-22 01:46:36 +07:00
from "${JDK_DIR}/templates/${platform.toString().toLowerCase()}"
}
copy{
into "build/packr/output/jre"
rename("${appName}.jar", "desktop.jar")
from "build/libs/${appName}.jar"
2019-08-22 01:46:36 +07:00
}
}else{
2021-06-05 07:19:11 +07:00
def jarPath = JDK_DIR + "packr.jar"
def args = ["java", "-jar", jarPath] as String[]
args += [
"--platform", platform == "MacOS" ? "Mac" : platform.toString(),
"--jdk", JDK_DIR + "jre-${platform.toString().toLowerCase()}",
"--executable", appName,
"--classpath", "$rootDir/desktop/build/packr/desktop.jar".toString(),
"--mainclass", project.ext.mainClassName,
"--verbose",
"--bundle", getPackage() + ".mac",
"--icon", ICON_DIR,
"--output", "$rootDir/desktop/build/packr/output".toString(),
"--removelibs", "$rootDir/desktop/build/packr/desktop.jar".toString()
]
2021-07-10 23:32:29 +07:00
args += "--vmargs"
2021-06-05 07:19:11 +07:00
if(platform == "MacOS"){
2021-07-10 23:32:29 +07:00
args += "XstartOnFirstThread"
2019-08-22 01:46:36 +07:00
}
2021-07-10 23:32:29 +07:00
args += "Dhttps.protocols=TLSv1.2,TLSv1.1,TLSv1"
2021-08-02 05:01:36 +07:00
args += "XX:+ShowCodeDetailsInExceptionMessages"
2021-07-10 23:32:29 +07:00
2021-06-05 07:19:11 +07:00
exec{
commandLine args.toList()
standardOutput = System.out
}
2019-08-22 01:46:36 +07:00
2021-06-05 07:19:11 +07:00
if(platform != "MacOS"){
2019-08-22 01:46:36 +07:00
copy{
into "build/packr/output/jre/"
from "build/packr/output/desktop.jar"
2019-08-22 01:46:36 +07:00
}
delete{
delete "build/packr/output/desktop.jar"
2019-08-22 01:46:36 +07:00
}
2021-06-05 07:19:11 +07:00
file("build/packr/output/Mindustry.json").text = file("build/packr/output/Mindustry.json").text.replace("desktop.jar", "jre/desktop.jar")
}else{
copy{
2019-08-24 21:00:04 +07:00
into "build/packr/output/${appName}.app/Contents/"
from "build/packr/output/Contents/"
}
delete{
2019-08-24 21:00:04 +07:00
delete "build/packr/output/Contents/"
}
}
}
2019-08-22 20:27:59 +07:00
2021-06-05 07:19:11 +07:00
if((platform == "Windows64" || platform == "Windows32")){
2019-08-25 22:16:38 +07:00
copy{
from "build/packr/output/jre/bin/msvcr100.dll"
into "build/packr/output/"
rename("msvcr100.dll", "MSVCR100.dll")
}
2019-11-08 02:58:51 +07:00
}
2019-11-07 01:59:35 +07:00
2019-11-08 02:58:51 +07:00
if(versionModifier.contains("steam")){
copy{
2021-06-05 07:19:11 +07:00
def lib = platform == "MacOS" || platform == "Linux64" ? "lib" : ""
from zipTree(platform == "MacOS" ? "build/packr/output/${appName}.app/Contents/Resources/desktop.jar" : "build/packr/output/jre/desktop.jar").matching{
include "${lib}steamworks4j${platform == "Windows64" ? '64.dll' : platform == "Windows32" ? '.dll' : platform == "Linux64" ? '.so' : '.dylib'}"
include "${lib}steam_api${platform == "Windows64" ? '64.dll' : platform == "Windows32" ? '.dll' : platform == "Linux64" ? '.so' : '.dylib'}"
2019-11-07 01:59:35 +07:00
}
2021-06-05 07:19:11 +07:00
into platform != "MacOS" ? "build/packr/output/" : "build/packr/output/${appName}.app/Contents/Resources"
2019-11-07 01:59:35 +07:00
}
2019-08-25 22:16:38 +07:00
}
2019-08-31 03:39:40 +07:00
2019-08-22 20:27:59 +07:00
copy{
from "build/packr/output"
into "../deploy/${platform.toString()}"
}
}
2019-04-08 20:03:18 +07:00
task "zip${platform.toString()}"(type: Zip){
from "build/packr/output"
2019-11-16 07:48:26 +07:00
archiveFileName = "${generateDeployName(platform.toString())}.zip"
destinationDirectory = (file("../deploy"))
doLast{
delete{
delete "build/packr/"
}
}
}
2018-02-01 04:05:43 +07:00
finalizedBy "zip${platform.toString()}"
2019-08-23 03:13:39 +07:00
2018-02-01 04:05:43 +07:00
}
2019-08-22 01:46:36 +07:00
}