generated from Anuken/MindustryJavaModTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
102 lines (79 loc) · 3.03 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
apply plugin: "java"
version '1.0'
sourceSets.main.java.srcDirs = ["src"]
repositories {
mavenCentral()
maven { url "https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository" }
maven { url 'https://www.jitpack.io' }
}
java {
targetCompatibility = 8
sourceCompatibility = JavaVersion.VERSION_17
}
ext {
// 本模组所针对的构建版本
mindustryVersion = 'v146'
jabelVersion = "93fde537c7"
// Windows 系统效果不好
isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
}
// Java 8 向后兼容标志
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs.addAll(['--release', '8'])
}
}
dependencies {
compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion"
compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion"
annotationProcessor "com.github.Anuken:jabel:$jabelVersion"
}
// 强制使用 Arc 版本
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.github.Anuken.Arc') {
details.useVersion "$mindustryVersion"
}
}
}
task jarAndroid {
dependsOn "jar"
doLast {
if (!sdkRoot || !new File(sdkRoot).exists())
throw new GradleException("未找到有效的 Android SDK. 请确保 ANDROID_HOME 设置为您的 Android SDK 目录。");
def platformRoot = new File("$sdkRoot/platforms/").listFiles().sort().reverse().find { f -> new File(f, "android.jar").exists() }
if (!platformRoot)
throw new GradleException("未找到 android.jar. 请确保您已安装 Android 平台。")
// 收集解析所需的依赖项
def dependencies = (configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList() + [new File(platformRoot, "android.jar")]).collect { "--classpath $it.path" }.join(" ")
def d8 = isWindows ? "d8.bat" : "d8"
// 进行 dex 和 desugar 文件 - 这需要 d8 在您的 PATH 中
"$d8 $dependencies --min-api 14 --output ${project.archivesBaseName}Android.jar ${project.archivesBaseName}Desktop.jar"
.execute(null, new File("$buildDir/libs")).waitForProcessOutput(System.out, System.err)
}
}
jar {
archiveFileName = "${base.archivesBaseName}Desktop.jar"
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
from(projectDir) {
include "mod.hjson"
}
from("assets/") {
include "**"
}
}
task deploy(type: Jar) {
dependsOn jarAndroid
dependsOn jar
archiveFileName = "${base.archivesBaseName}.jar"
from { [zipTree("$buildDir/libs/${project.archivesBaseName}Desktop.jar"), zipTree("$buildDir/libs/${project.archivesBaseName}Android.jar")] }
doLast {
delete {
delete "$buildDir/libs/${project.archivesBaseName}Desktop.jar"
delete "$buildDir/libs/${project.archivesBaseName}Android.jar"
}
}
}