-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
286 lines (238 loc) · 10.3 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
plugins {
id "io.github.pacifistmc.forgix" version "1.2.6"
id "org.ajoberstar.grgit" version "4.1.0"
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
id "systems.manifold.manifold-gradle-plugin" version "0.0.2-alpha"
}
group = 'com.mrmelon54.infrastructury'
version = '1.0-SNAPSHOT'
repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/releases/" }
maven { url "https://maven.parchmentmc.org" }
maven { url "https://maven.fabricmc.net" }
}
project.gradle.ext.getProperties().each { prop ->
rootProject.ext.set(prop.key, prop.value)
}
import groovy.json.JsonSlurper
static def generateForgeVersions(mc_versions) {
def json = new JsonSlurper().parseText(mc_versions) as List<String>
if (json.size() == 0) {
return "error"
}
return "[" + json[0] + "," + json[json.size() - 1] + "]"
}
rootProject.versionStr = "${rootProject.mod_version}-mc${rootProject.minecraft_version}"
rootProject.compatible_forge_versions = generateForgeVersions(rootProject.compatible_minecraft_versions)
rootProject.forgix_merged_jar = "${project.archives_base_name}-${rootProject.versionStr}-${getVersionMetadata()}.jar"
// Remap architectury
import net.fabricmc.tinyremapper.NonClassCopyMode
import net.fabricmc.tinyremapper.OutputConsumerPath
import net.fabricmc.tinyremapper.TinyRemapper
import net.fabricmc.tinyremapper.TinyUtils
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.security.MessageDigest
var mappingsProjectDir = project(":mappings").projectDir.toPath()
var mappingsTinyFile = new File(mappingsProjectDir.resolve("arch_${rootProject.architectury_version}.tiny").toUri())
var hashHex = HexFormat.of().formatHex(MessageDigest.getInstance("SHA-1").digest(mappingsTinyFile.readBytes()))
static void runMappingsOnJar(File input, File output, File mappingsTiny, String fromM, String toM) {
def remapper = TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappingsTiny.toPath(), fromM, toM))
.renameInvalidLocals(false)
.build()
output.delete()
try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output.toPath()).build()) {
outputConsumer.addNonClassFiles(input.toPath(), NonClassCopyMode.FIX_META_INF, remapper)
remapper.readInputs(input.toPath())
remapper.readClassPath(input.toPath())
remapper.apply(outputConsumer)
} catch (IOException e) {
throw new RuntimeException(e)
} finally {
remapper.finish()
}
}
subprojects { p ->
if (findProject(":mappings") && p == project(":mappings")) return
apply plugin: "java"
apply plugin: "dev.architectury.loom"
apply plugin: "systems.manifold.manifold-gradle-plugin"
loom {
silentMojangMappingsLicense()
}
// set up custom configurations (configurations are a way to handle dependencies)
configurations {
compile
mappings
addArchApi
// extends the shadowJar configuration
shadowMe
// have implemented dependencies automatically embedded in the final jar
implementation.extendsFrom(shadowMe)
forgeShadowMe
implementation.extendsFrom(forgeShadowMe)
shadowMe.extendsFrom(forgeShadowMe)
forgeRuntimeLibrary.extendsFrom(forgeShadowMe)
// if (p != project(":common")) {
// // Shadow common
// common
// shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
// compileClasspath.extendsFrom common
// runtimeClasspath.extendsFrom common
// if (findProject(":forge"))
// developmentForge.extendsFrom common
// if (findProject(":neoforge"))
// developmentNeoForge.extendsFrom common
// compileClasspath.extendsFrom coreProjects
// runtimeClasspath.extendsFrom coreProjects
// if (findProject(":forge"))
// developmentForge.extendsFrom coreProjects
// if (findProject(":neoforge"))
// developmentNeoForge.extendsFrom coreProjects
// }
}
String platformStr = ""
if (findProject(":common") && p != project(":common")) {
if (findProject(":quilt") && p == project(":quilt")) platformStr = "-fabric"
else platformStr = "-${p.name}"
}
File remappedArchFile = new File(rootProject.projectDir, ".gradle/remapped_architectury_cache/${hashHex}/remapped-architectury-${p.name}-${rootProject.architectury_version}.jar")
dependencies {
annotationProcessor("systems.manifold:manifold-preprocessor:${rootProject.manifold_version}")
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${rootProject.parchment_version}@zip")
}
if (p.name == "quilt") {
addArchApi("${rootProject.architectury_group}:architectury-fabric:${rootProject.architectury_version}") {
exclude group: "net.fabricmc"
exclude group: "net.fabricmc.fabric-api"
}
} else {
addArchApi "${rootProject.architectury_group}:architectury${platformStr}:${rootProject.architectury_version}"
}
if (findProject(":common") && p != project(":common")) {
common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProduction${capitalProject(p.name)}")) { transitive false }
}
if (findProject(":mappings") && p != project(":mappings")) {
dependencies {
modApi files(remappedArchFile.toPath())
}
}
}
repositories {
maven { url "https://maven.shedaniel.me/" }
}
if (findProject(":mappings") && p != project(":mappings")) {
tasks.register('applyMappings') {
if (!remappedArchFile.exists()) {
var archJarPath = "/architectury${platformStr}-${rootProject.architectury_version}.jar"
println "Searching for architectury jar: $archJarPath"
File archJar = configurations.addArchApi.files.find { it.path.endsWith(archJarPath) }
println "Found matching jar: ${archJar.name}"
println "Using mappings: ${mappingsTinyFile.name}"
runMappingsOnJar(archJar, remappedArchFile, mappingsTinyFile, "official", "named")
println "Remapping completed successfully."
}
return
}
compileJava.dependsOn applyMappings
tasks.register('undoApplyMappings') {
doLast {
File mergedJar = new File(rootProject.layout.projectDirectory.asFile, "Merged/${rootProject.forgix_merged_jar}")
if (!mergedJar.exists()) throw new GradleException("Missing merged output jar")
File remapFile = new File(mergedJar.parentFile, mergedJar.name + ".remapped.jar")
runMappingsOnJar(mergedJar, remapFile, mappingsTinyFile, "named", "official")
mergedJar.delete()
Files.copy(remapFile.toPath(), mergedJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
remapFile.delete()
}
}
rootProject.tasks['mergeJars'].finalizedBy undoApplyMappings
}
}
static def capitalProject(String value) {
if (value == "neoforge") return "NeoForge"
return value[0].toUpperCase() + value.substring(1)
}
allprojects {
apply plugin: "java"
apply plugin: "architectury-plugin"
apply plugin: "maven-publish"
archivesBaseName = "${rootProject.archives_base_name}-${project.name}"
version = rootProject.versionStr
group = rootProject.maven_group
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/releases/" }
maven { url "https://maven.parchmentmc.org" }
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = rootProject.java_version as Integer
options.compilerArgs += ["-Xplugin:Manifold"]
}
processResources {
exclude { file ->
if (file.name.contains(".${mod_id}.accesswidener") && file.name != "${accessWidenerVersion}.${mod_id}.accesswidener") {
return true
}
return false
}
}
java {
withSourcesJar()
}
publishing {
repositories {
maven {
credentials {
username = "melon"
password = System.getenv("MAVEN_PASS")
}
switch (System.getenv("MAVEN_TYPE")) {
case "production": url = "https://maven.mrmelon54.com/releases"; break
case "development": url = "http://localhost:8080/snapshots"; break
default: url = "https://maven.mrmelon54.com/snapshots"; break
}
}
}
}
}
def getVersionMetadata() {
def build_id = System.getenv("GITHUB_RUN_NUMBER")
// CI builds only
if (build_id != null) {
return "build.${build_id}"
}
if (grgit != null) {
def head = grgit.head()
def id = head.abbreviatedId
// Flag the build if the build tree is not clean
if (!grgit.status().clean) {
id += "-dirty"
}
return "rev.${id}"
}
// No tracking information could be found about the build
return "unknown"
}
// Delete the merged folder when running clean
task cleanMergedJars() {
def mergedFolder = file("Merged")
if (mergedFolder.exists()) {
delete(mergedFolder)
}
}
// add cleanMergedJars to the end of the "clean" task
tasks["clean"].finalizedBy(cleanMergedJars)