-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
263 lines (225 loc) · 9.07 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import java.time.format.DateTimeFormatter
buildscript{
ext{
mainPackage = "yourmod";
// v7
mindustryPath = "com.github.Anuken.MindustryJitpack"
//the build number that this mod is made for
mindustryVersion = "68f053f409"
arcVersion = "ef9d6ac655"
//v6
//mindustryPath = "com.github.Anuken.Mindustry"
//the build number that this mod is made for
//mindustryVersion = 'v135'
//arcVersion=mindustryVersion
modCoreVersion = "a91c0520e04"
kotlinVersion = "1.6.0"
jabelVersion = "0.7.0"
}
repositories{
mavenLocal()
mavenCentral()
// google()
maven{ url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven{ url 'https://jitpack.io' }
}
dependencies{
classpath "com.github.Anuken.Arc:arc-core:$arcVersion"
classpath "$mindustryPath:core:$mindustryVersion"
classpath "com.github.Anuken.Arc:packer:$arcVersion"
classpath "com.github.Zelaux.ZelauxModCore:annotations:$modCoreVersion"
}
}
plugins{
id 'org.jetbrains.kotlin.jvm' version "$kotlinVersion"
id "org.jetbrains.kotlin.kapt" version "$kotlinVersion"
}
ext{
sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
arcModule = { String name ->
//skip to last submodule
if(name.contains(':')) name = name.split(':').last()
return "com.github.Anuken.Arc:$name:$arcVersion"
}
coreModule = { String name ->
//skip to last submodule
if(name.contains(':')) name = name.split(':').last()
return "com.github.Zelaux.ZelauxModCore:$name:$modCoreVersion"
}
writeProcessors = {
new File(rootDir, "annotations/src/main/resources/META-INF/services/").mkdirs()
def processorFile = new File(rootDir, "annotations/src/main/resources/META-INF/services/javax.annotation.processing.Processor")
def text = new StringBuilder()
def files = new File(rootDir, "annotations/src/main/java")
files.eachFileRecurse(
groovy.io.FileType.FILES
){ file ->
boolean isProcessor = file.text.contains(" extends ModBaseProcessor") ||
(file.text.contains(" extends AbstractProcessor") && !file.text.contains("abstract class")) ||
file.text.contains("@ModAnnotations.AnnotationProcessor");
if(file.name.endsWith(".java") && isProcessor){
text.append(file.path.substring(files.path.length() + 1)).append("\n")
}
}
processorFile.text = text.toString().replace(".java", "").replace("/", ".").replace("\\", ".")
}
}
apply plugin: 'java'
version '1.0'
allprojects{
apply plugin: 'maven-publish'
repositories{
mavenLocal()
google()
mavenCentral()
maven{ url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven{ url "https://oss.sonatype.org/content/repositories/releases/" }
maven{ url 'https://jitpack.io' }
}
tasks.withType(JavaCompile){
targetCompatibility = 8
//switch to JavaVersion.VERSION_17 to use Java 17 features; this requires adding jabel (see dependencies block below)
sourceCompatibility = 8
options.encoding = "UTF-8"
options.compilerArgs += ["-Xlint:deprecation"]
options.forkOptions.jvmArgs.addAll([
'--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED'
])
}
}
//compile with java 8 compatibility for everything except the annotation project
configure(subprojects - project(":annotations")){
tasks.withType(JavaCompile){
options.compilerArgs.addAll(['--release', '8'])
}
tasks.withType(Javadoc){
options{
addStringOption('Xdoclint:none', '-quiet')
addStringOption('-release', '16')
}
}
}
project(":core"){
apply plugin: "java-library"
apply plugin: "kotlin"
apply plugin: "kotlin-kapt"
kapt{
javacOptions{
option("-source", "16")
option("-target", "1.8")
}
}
compileJava.options.fork = true
task preGen{
outputs.upToDateWhen{ false }
writeProcessors()
}
dependencies{
compileJava.dependsOn(preGen)
implementation coreModule("core")
implementation coreModule("graphics")
// implementation coreModule("utils")//extra module
// implementation coreModule("blocks")//extra module
compileOnly "org.lz4:lz4-java:1.7.1"
compileOnly arcModule("arc-core")
compileOnly arcModule("extensions:flabel")
compileOnly arcModule("extensions:freetype")
compileOnly arcModule("extensions:g3d")
compileOnly arcModule("extensions:fx")
compileOnly arcModule("extensions:arcnet")
compileOnly "$mindustryPath:core:$mindustryVersion"
//you may uncomment this dependency to properly use Java 17 features while still targeting Java 8.
//note that this fails on some systems for as-of-yet unknown reasons - if this happens to you, revert the changes
//annotationProcessor "com.github.Anuken:jabel:$jabelVersion"
// annotationProcessor 'com.github.Anuken:jabel:34e4c172e65b3928cd9eabe1993654ea79c409cd'
compileOnly "com.github.Zelaux.ZelauxModCore:annotations:$modCoreVersion"
compileOnly project(":annotations")
kapt project(":annotations")
}
jar{
exclude(mainPackage + "/entities/comp/**")
}
}
task jarAndroid{
dependsOn "jar"
doLast{
if(!sdkRoot || !new File(sdkRoot).exists()) throw new GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory.");
def platformRoot = new File("$sdkRoot/platforms/").listFiles().sort().reverse().find{ f -> new File(f, "android.jar").exists() }
if(!platformRoot) throw new GradleException("No android.jar found. Ensure that you have an Android platform installed.")
//collect dependencies needed for desugaring
def dependencies = (project(":core").configurations.compileClasspath.asList() + project(":core").configurations.runtimeClasspath.asList() + [new File(platformRoot, "android.jar")])
.collect{ "--classpath $it.path" }.join(" ")
//dex and desugar files - this requires d8 in your 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{
dependsOn "core:jar"
archiveFileName = "${project.archivesBaseName}Desktop.jar"
from{
// configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
project(":core").fileTree("build/libs/core.jar").collect{ it.isDirectory() ? it : zipTree(it) }
}
from{
project(":core").configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it) }
// project(":core").fileTree("build/libs/core.jar").collect { it.isDirectory() ? it : zipTree(it) }
}
from(rootDir){
include "mod.hjson"
include "mod.json"
include "icon.png"
}
from("core/assets/"){
include "**"
}
}
task deploy(type: Jar){
dependsOn jarAndroid
dependsOn jar
archiveFileName = "${project.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{ delete "$buildDir/libs/${project.archivesBaseName}Android.jar" }
}
}
task mjar(){
dependsOn "jar"
ext{
move = { String intoPath ->
delete{
delete "${intoPath}/${project.archivesBaseName}Desktop.jar"
}
copy{
from "$buildDir/libs/${project.archivesBaseName}Desktop.jar"
into intoPath
}
println "Moved into " + intoPath
}
}
doLast{
def modsDirectories = [];
def file = new File(rootDir, "modsDirectories.txt");
// println "abs->"+file.getAbsolutePath();
if(file.exists()){
BufferedReader reader = new BufferedReader(new FileReader(file));
reader.lines().forEach(line -> modsDirectories.add(line))
}else{
modsDirectories.add("classic");
}
for(String directory : modsDirectories){
if (directory.startsWith("#") || directory.startsWith("//")){
println "Directory \"$directory\" was skipped."
continue
}
if(directory.equals("classic")){
directory = "${arc.util.OS.getAppDataDirectoryString("Mindustry")}/mods/";
}
move(directory);
}
def time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
println "Build ended at: ${time}"
}
}