-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbuild.gradle
311 lines (268 loc) · 11.4 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import me.modmuss50.mpp.ReleaseType
buildscript {
// Unify build logic of all submodules in here, ugly but easier since we have to deal with a lot random stuff
repositories {
gradlePluginPortal()
maven {
url = "https://maven.minecraftforge.net/"
}
maven {
url = "https://repo.spongepowered.org/repository/maven-public/"
}
}
dependencies {
classpath "com.gradleup.shadow:shadow-gradle-plugin:8.3.5"
classpath "net.minecraftforge.gradle:ForgeGradle:[6.0.24,6.2)"
classpath "org.spongepowered:mixingradle:0.7-SNAPSHOT"
classpath "xyz.wagyourtail.jvmdowngrader:gradle-plugin:1.0.1"
classpath "me.modmuss50.mod-publish-plugin:me.modmuss50.mod-publish-plugin.gradle.plugin:0.8.4"
}
}
allprojects {
apply plugin: "java-library"
apply plugin: "com.gradleup.shadow"
apply plugin: "xyz.wagyourtail.jvmdowngrader"
java {
// Minecraft 1.17+ required Java 17 to compile,
// Minecraft 1.20.5+ required Java 21 to compile
toolchain.languageVersion = JavaLanguageVersion.of(21)
}
// Always set min java version to 17, for java 8 versions the jar is manually downgraded so it doesn't matter.
compileJava.setSourceCompatibility("17")
compileJava.setTargetCompatibility("17")
// Configuration used to include dependencies to the final jars
configurations {
library
implementation.extendsFrom(library)
}
repositories {
maven {
url = "https://maven.minecraftforge.net/"
}
maven {
url = "https://repo.spongepowered.org/repository/maven-public"
}
maven {
url = "https://maven.neoforged.net/"
}
maven {
url = "https://repo.viaversion.com"
metadataSources {
// Prevent Gradle from checking against correct Java version, needed since we downgrade libraries
// on include
mavenPom()
artifact()
}
}
}
dependencies {
library "com.viaversion:viaversion-common:5.2.2-SNAPSHOT"
library "com.viaversion:viabackwards-common:5.2.2-SNAPSHOT"
library "com.viaversion:viarewind-common:4.0.6-SNAPSHOT"
library "com.viaversion:viaaprilfools-common:4.0.1-SNAPSHOT"
library ("com.viaversion:vialoader:4.0.1-SNAPSHOT") {
exclude group: "com.google.guava"
exclude group: "org.slf4j"
}
library ("net.raphimc:ViaLegacy:3.0.8-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson"
}
}
}
subprojects {
def applyFg = project.hasProperty("applyFg") ? Boolean.parseBoolean(project.applyFg) : true
if (applyFg) {
apply plugin: "net.minecraftforge.gradle"
apply plugin: "org.spongepowered.mixin"
}
apply plugin: "me.modmuss50.mod-publish-plugin"
// Define the jar output attributes for all platforms
base {
group = project.maven_group
archivesName = project.name
version = project.maven_version
description = project.maven_description
}
// Get the game version (1.16.5) from the forge version
// Kinda ugly but easier than having multiple constants
def mcVersion = project.hasProperty("mcVersion") ? project.mcVersion : project.forge_version.split("-")[0]
// Used to execute code only for specific submodules
def versionId = Integer.parseInt(mcVersion.replace(".", ""))
// Java 17 is default, set newer versions here
if (versionId >= 1_20_6) {
compileJava.setSourceCompatibility("21")
compileJava.setTargetCompatibility("21")
}
compileJava.options.encoding = "UTF-8"
if (applyFg) {
minecraft {
// Unify to mojang mappings for 1.14+, MCP for below
if (versionId >= 1_16_5) {
mappings channel: "official", version: mcVersion
}
runs {
client {
workingDirectory project.file("run")
property "forge.logging.markers", "REGISTRIES"
property "forge.logging.console.level", "debug"
// mixin
property "mixin.debug.export", "true"
property "mixin.hotSwap", "true"
property "fml.coreMods.load", "de.florianmichael.viaforge.mixin.MixinLoader"
// Only required for MC 1.12, but modern Forges skips this anyway
args "-mixin.config=" + "mixins." + project.getProperty('name') + ".json"
// source set
mods {
"${project.name}" {
source sourceSets.main
}
}
}
}
}
sourceSets.main.resources {
srcDir "src/generated/resources"
}
dependencies {
minecraft "net.minecraftforge:forge:${forge_version}"
library "org.slf4j:slf4j-api:2.0.16"
if (versionId < 1_20_6) {
// Always include for refmap in versions that don't have official mappings at runtime,
// later exclude classes to prevent loading conflicts...
library "org.spongepowered:mixin:${mixin_version}"
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
}
if (versionId >= 1_20_6) {
// NeoForge, only to compile against
compileOnly("net.neoforged.fancymodloader:loader:2.0.20") { transitive = false }
compileOnly("net.neoforged:bus:7.2.0") { transitive = false }
}
library project(":") // Include the base project
}
// Replace the version in the mcmod.info and mods.toml files with the project version
// Since this depends on the platform version, we can't define it in the global scope :(
tasks {
processResources {
for (final def file in ["mcmod.info", "META-INF/mods.toml"]) {
filesMatching(file) {
expand(
"version": project.version,
"description": project.description
)
}
}
}
}
mixin {
add sourceSets.main, "mixins.${project.name}.refmap.json"
}
// 1. jar
// 2. shadowJar
// 3. downgradeJar and shadeDowngradedApi
// 4. re-obfuscate the shadowJar
jar {
manifest.attributes(
"Specification-Title": project.name,
"Specification-Vendor": "FlorianMichael/EnZaXD <[email protected]>",
"Specification-Version": project.version,
"Implementation-Title": project.name,
"Implementation-Vendor": "FlorianMichael/EnZaXD <[email protected]>",
"Implementation-Version": project.version,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd" - "HH:mm:ssZ"),
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
"TweakOrder": "0",
"FMLCorePluginContainsFMLMod": "true", // Only required for MC 1.12, but modern Forges skips this anyway
"FMLCorePlugin": "de.florianmichael.viaforge.mixin.MixinLoader", // Counterpart to the above
"MixinConfigs": "mixins.${project.name}.json",
"ForceLoadAsMod": "true"
)
enabled = false
}
shadowJar {
if (versionId >= 1_17_1) {
archiveFileName = jar.archiveFileName
} else {
destinationDirectory = temporaryDir
}
configurations = [project.configurations.library] // Include the dependencies from the include configuration
duplicatesStrategy DuplicatesStrategy.EXCLUDE
// Prevent conflicts with Forge's weird service loading
exclude("META-INF/maven/**")
exclude("META-INF/versions/**")
if (versionId >= 1_13_2) {
// We don't need to package mixins into Forge 1.13+ jars, since Forge already has it
exclude("org/spongepowered/**")
}
if (versionId >= 1_16_5) {
// Get rid of the services folder, since Forge 1.16+ would conflict with some of the ForgeDev Environment's services
// And since we don't need them for Mixins anyway, we can just exclude them from the shadowJar
exclude("META-INF/services/**")
}
// Workaround GH-94
relocate("org.slf4j", "com.viaversion.vialoader.libs.slf4j")
}
downgradeJar {
inputFile = shadowJar.archiveFile
destinationDirectory = temporaryDir
}
shadeDowngradedApi {
archiveFileName = jar.archiveFileName
}
if (versionId < 1_20_6) { // Use official mappings at runtime, otherwise re-obfuscate output
reobf {
shadowJar {}
}
}
jar.dependsOn("shadowJar")
if (versionId < 1_17_1) {
// Downgrade the jar to Java 8 for Minecraft 1.16.5 and below
jar.dependsOn("shadeDowngradedApi")
}
}
publishMods {
if (project.name == "viaforge-mc189") { // Special handle dummy module...
def folder = project.file("publishMods")
if (!folder.exists() || folder.listFiles().length != 1) {
return
}
file = folder.listFiles()[0]
} else if (versionId < 1_17_1) { // FG's reobfuscation will rename the jar in place, so use the one *before* finalizing the jar
file = tasks.shadeDowngradedApi.archiveFile
} else {
file = tasks.shadowJar.archiveFile
}
changelog = rootProject.file("CHANGELOG").text
version = project.version.toString() + "+" + mcVersion
displayName = "ViaForge " + project.version.toString() + " (MC $mcVersion)"
modLoaders.add("forge")
type = ReleaseType.STABLE
dryRun = !rootProject.hasProperty("curseforge_publish_token") || !rootProject.hasProperty("modrinth_publish_token")
curseforge {
if (rootProject.hasProperty("curseforge_publish_token")) {
accessToken = rootProject.property("curseforge_publish_token")
}
projectId = "418933"
if (versionId < 1_17_1) {
javaVersions.add(JavaVersion.VERSION_1_8)
} else if (versionId < 1_20_6) {
javaVersions.add(JavaVersion.VERSION_17)
} else {
javaVersions.add(JavaVersion.VERSION_21)
}
minecraftVersions.add(mcVersion.toString())
clientRequired = true
}
modrinth {
if (rootProject.hasProperty("modrinth_publish_token")) {
accessToken = rootProject.property("modrinth_publish_token")
}
projectId = "Z6se2s8f"
minecraftVersions.add(mcVersion.toString())
}
}
// Make sure to have the re-obfuscated jar for publishing
tasks.publishMods.dependsOn tasks.build
}
dependencies {
compileOnly "io.netty:netty-all:4.1.117.Final"
}