-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.gradle.kts
297 lines (256 loc) · 9.93 KB
/
build.gradle.kts
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
287
288
289
290
291
292
293
294
295
296
297
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.minecraftforge.gradle.common.util.RunConfig
import net.minecraftforge.jarjar.metadata.*
import org.apache.maven.artifact.versioning.DefaultArtifactVersion
import org.apache.maven.artifact.versioning.VersionRange
import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.time.LocalDateTime
plugins {
java
`maven-publish`
id("net.minecraftforge.gradle") version "[6.0,6.2)"
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
id("org.spongepowered.mixin") version "0.7.+"
}
version = "1.0"
group = "dev.su5ed.sinytra"
val versionMc: String by project
val versionForge: String by project
val versionForgeAutoRenamingTool: String by project
val versionFabricLoader: String by project
val versionAccessWidener: String by project
val versionFabricApi: String by project
val versionMixin: String by project
val language by sourceSets.registering
val mod: SourceSet by sourceSets.creating
val shade: Configuration by configurations.creating
val shadeRuntimeOnly: Configuration by configurations.creating
val depsJar: ShadowJar by tasks.creating(ShadowJar::class) {
configurations = listOf(shade, shadeRuntimeOnly)
exclude("assets/fabricloader/**")
exclude("META-INF/**")
exclude("ui/**")
exclude("*.json")
exclude("module-info.class")
exclude("LICENSE.txt")
dependencies {
exclude(dependency("org.ow2.asm:"))
exclude(dependency("net.sf.jopt-simple:"))
exclude(dependency("com.google.guava:guava"))
exclude(dependency("com.google.code.gson:gson"))
}
archiveClassifier.set("deps")
}
val languageJar: Jar by tasks.creating(Jar::class) {
dependsOn("languageClasses")
from(language.get().output)
manifest.attributes("FMLModType" to "LANGPROVIDER")
archiveClassifier.set("language")
}
// We need fabric loader to be present on the service layer. In order to do that, we use shadow jar to ship it ourselves.
// However, this easily creates conflicts with other mods that might be providing it via JarInJar. To avoid this conflict,
// we provide a dummy nested jar with the same identifier, but a "max" version, so that it always takes priority over
// nested jars shipped by other mods, effectively disabling them.
val dummyFabricLoaderVersion = "999.999.999"
// This is the actualy dummy jar, set to a LIBRARY type to be put on the PLUGIN layer
val dummyFabricLoaderLangJar: Jar by tasks.creating(Jar::class) {
manifest.attributes(
"FMLModType" to "LIBRARY",
"Implementation-Version" to dummyFabricLoaderVersion
)
archiveClassifier.set("fabricloader")
}
// Generate JarJar metadata manually so that we control both the version and the file path
val createJarJarMetadata: Task by tasks.creating {
val jarPath = "META-INF/jarjar/" + dummyFabricLoaderLangJar.archiveFile.get().asFile.name
val output = project.layout.buildDirectory.dir("createJarJarMetadata").get().file("metadata.json")
inputs.property("jarPath", jarPath)
outputs.file(output)
extra["output"] = output
doFirst {
val metadata = Metadata(listOf(ContainedJarMetadata(
ContainedJarIdentifier("dev.su5ed.sinytra", "fabric-loader"),
ContainedVersion(VersionRange.createFromVersion("[$dummyFabricLoaderVersion,)"), DefaultArtifactVersion(dummyFabricLoaderVersion)),
jarPath,
false
)))
Files.deleteIfExists(output.asFile.toPath())
Files.write(output.asFile.toPath(), MetadataIOHandler.toLines(metadata), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)
}
}
// ShadowJar doesn't support nesting archives - it will flatten them if they're included. Therefore, we must first preprocess
// the jar contents with shadow before creating the final bundle that also includes the dummy nested jar.
val prepareModJar: ShadowJar by tasks.creating(ShadowJar::class) {
dependsOn("modClasses")
from(mod.output)
relocate("org.spongepowered.asm", "org.spongepowered.reloc.asm")
archiveClassifier.set("prepare-mod")
}
val modJar: Jar by tasks.creating(Jar::class) {
from(zipTree(prepareModJar.archiveFile))
into("META-INF/jarjar/") {
from(createJarJarMetadata)
from(dummyFabricLoaderLangJar)
}
manifest.attributes("ConnectorMixinConfigs" to "connectormod.mixins.json")
archiveClassifier.set("mod")
}
val remappedDepsJar: ShadowJar by tasks.creating(ShadowJar::class) {
dependsOn(depsJar)
from(tasks.jar)
from(depsJar.archiveFile)
mergeServiceFiles() // Relocate services
relocate("org.spongepowered.asm", "org.spongepowered.reloc.asm")
relocate("org.spongepowered.include", "org.spongepowered.reloc.include")
relocate("org.spongepowered.tools", "org.spongepowered.reloc.tools")
relocate("net.minecraftforge.fart", "net.minecraftforge.reloc.fart")
relocate("net.minecraftforge.srgutils", "net.minecraftforge.reloc.srgutils")
relocate("net.fabricmc.accesswidener", "net.fabricmc.reloc.accesswidener")
relocate("MixinConfigs", "ConnectorMixinConfigs")
archiveClassifier.set("deps-reloc")
}
val fullJar: Jar by tasks.creating(Jar::class) {
mustRunAfter("reobfModJar")
from(zipTree(remappedDepsJar.archiveFile))
from(languageJar)
from(modJar)
manifest.attributes("Embedded-Dependencies-Language" to languageJar.archiveFile.get().asFile.name)
manifest.attributes("Embedded-Dependencies-Mod" to modJar.archiveFile.get().asFile.name)
archiveClassifier.set("full")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
withSourcesJar()
}
mixin {
add(mod, "mixins.connectormod.refmap.json")
}
reobf {
create("modJar") {
dependsOn(modJar)
}
}
configurations {
compileOnly {
extendsFrom(shade)
}
"languageImplementation" {
extendsFrom(configurations.minecraft.get(), shade)
}
"modCompileOnly" {
extendsFrom(configurations.compileOnly.get())
}
"modImplementation" {
extendsFrom(configurations.minecraft.get(), shade)
}
"modAnnotationProcessor" {
extendsFrom(configurations.annotationProcessor.get())
}
}
sourceSets {
main {
runtimeClasspath = runtimeClasspath.minus(output).plus(files(fullJar))
}
}
println("Java: ${System.getProperty("java.version")}, JVM: ${System.getProperty("java.vm.version")} (${System.getProperty("java.vendor")}), Arch: ${System.getProperty("os.arch")}")
minecraft {
mappings("official", versionMc)
runs {
val config = Action<RunConfig> {
property("forge.logging.console.level", "debug")
property("forge.logging.markers", "REGISTRIES,SCAN,FMLHANDSHAKE,COREMOD")
property("connector.logging.markers", "MIXINPATCH,MERGER")
property("mixin.debug", "true")
// property("connector.cache.enabled", "false")
workingDirectory = project.file("run").canonicalPath
mods {
create("connector") {
sources(sourceSets.main.get())
}
}
val existing = lazyTokens["minecraft_classpath"]
lazyToken("minecraft_classpath") {
fullJar.archiveFile.get().asFile.absolutePath
.let { path -> existing?.let { "$path;${it.get()}" } ?: path }
}
}
create("client", config)
create("server", config)
create("data") {
config(this)
args(
"--mod", "connector",
"--all",
"--output", file("src/generated/resources/"),
"--existing", file("src/main/resources/")
)
}
}
}
// Include resources generated by data generators.
sourceSets.main {
resources {
srcDir("src/generated/resources")
}
}
repositories {
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net")
}
maven {
name = "Su5eD"
url = uri("https://maven.su5ed.dev/releases")
}
}
dependencies {
minecraft(group = "net.minecraftforge", name = "forge", version = "$versionMc-$versionForge")
shade(group = "dev.su5ed.sinytra", name = "fabric-loader", version = versionFabricLoader) { isTransitive = false }
shade(group = "net.fabricmc", name = "access-widener", version = versionAccessWidener)
shade(group = "dev.su5ed.sinytra", name = "ForgeAutoRenamingTool", version = versionForgeAutoRenamingTool)
shadeRuntimeOnly(group = "dev.su5ed.sinytra", name = "sponge-mixin", version = versionMixin) { isTransitive = false }
annotationProcessor(group = "dev.su5ed.sinytra", name = "sponge-mixin", version = versionMixin)
compileOnly(group = "dev.su5ed.sinytra.fabric-api", name = "fabric-api", version = versionFabricApi)
runtimeOnly(fg.deobf("dev.su5ed.sinytra.fabric-api:fabric-api:$versionFabricApi"))
"languageCompileOnly"(sourceSets.main.get().output)
"modCompileOnly"(sourceSets.main.get().output)
}
tasks {
jar {
finalizedBy("reobfJar")
manifest {
attributes(
"Specification-Title" to project.name,
"Specification-Vendor" to "Sinytra",
"Specification-Version" to "1",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to "Sinytra",
"Implementation-Timestamp" to LocalDateTime.now()
)
}
}
withType<JavaCompile> {
options.encoding = "UTF-8" // Use the UTF-8 charset for Java compilation
}
assemble {
dependsOn("reobfModJar", fullJar)
}
configureEach {
if (name == "prepareRuns") {
dependsOn(fullJar)
}
if (name == "addMixinsToJar") {
enabled = false
}
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
suppressAllPomMetadataWarnings()
from(components["java"])
}
}
}