forked from tr7zw/ProcessedModTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.gradle
359 lines (298 loc) · 11 KB
/
common.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
import net.raphimc.javadowngrader.gradle.task.DowngradeJarTask
import org.objectweb.asm.Opcodes
plugins {
id "dev.architectury.loom" version "1.9-SNAPSHOT" apply false
id 'com.gradleup.shadow' version '9.0.0-beta4' apply false
id "com.diffplug.spotless" version "7.0.0.BETA4" apply false
id "net.raphimc.java-downgrader" version "1.1.2-SNAPSHOT" apply false
// This dependency is only used to determine the state of the Git working tree so that build artifacts can be
// more easily identified. This setup is copied from sodium
id 'org.ajoberstar.grgit' version '5.2.1'
}
apply plugin: 'eclipse'
apply plugin: "dev.architectury.loom"
apply plugin: 'com.replaymod.preprocess'
apply plugin: 'com.gradleup.shadow'
apply plugin: 'net.raphimc.java-downgrader'
def mod_brand = (loom.platform.get() as String).toLowerCase()
assert mod_brand in ['fabric', 'forge', 'neoforge']
assert project.name.endsWith('-' + mod_brand) // optional check
int mcVersion = 1
preprocess {
mcVersion = vars.get()["MC"] as int
tabIndentation = false
vars.put("MC", mcVersion)
vars.put("FABRIC", mod_brand == 'fabric' ? 1 : 0)
vars.put("FORGE", mod_brand == 'forge' ? 1 : 0)
vars.put("NEOFORGE", mod_brand == 'neoforge' ? 1 : 0)
}
loom {
if (!(mod_brand == 'neoforge' || (mod_brand == 'forge' && mcVersion >= 12005))) {
println "Creating refmap for version $mcVersion"
mixin {
useLegacyMixinAp = true
defaultRefmapName = "$id$.refmap.mixins.json"
}
}
runConfigs.all {
// to make sure it generates all "Minecraft Client (:subproject_name)" applications
ideConfigGenerated = true
runDir '../../run'
}
silentMojangMappingsLicense()
if (mod_brand == 'forge') {
forge.mixinConfigs "${modid}.mixins.json"
}
if(file("${project.rootProject.rootDir}/src/main/resources/$id$.accesswidener").exists()){
accessWidenerPath = file("${project.rootProject.rootDir}/src/main/resources/$id$.accesswidener")
}
if(file("$projectDir/src/main/resources/$id$.accesswidener").exists()){
accessWidenerPath = file("$projectDir/src/main/resources/$id$.accesswidener")
}
}
configurations {
inc
implementation.extendsFrom inc
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.layered() {
officialMojangMappings()
if (mcVersion >= 12100) {
parchment("org.parchmentmc.data:parchment-${rootProject.parchment_mc_version_21}:${rootProject.parchment_version_21}@zip")
} else if (mcVersion >= 12004) {
parchment("org.parchmentmc.data:parchment-${rootProject.parchment_mc_version_20_4}:${rootProject.parchment_version_20_4}@zip")
} else if(mcVersion >= 12002) {
parchment("org.parchmentmc.data:parchment-${rootProject.parchment_mc_version_20_2}:${rootProject.parchment_version_20_2}@zip")
}
}
compileOnly 'org.projectlombok:lombok:1.18.36'
annotationProcessor 'org.projectlombok:lombok:1.18.36'
testCompileOnly 'org.projectlombok:lombok:1.18.36'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.36'
if (mod_brand == 'fabric') {
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
if(project.hasProperty('mod_menu_compile_only')) {
modCompileOnly "maven.modrinth:modmenu:${project.mod_menu_release}"
} else {
modImplementation "maven.modrinth:modmenu:${project.mod_menu_release}"
}
testImplementation "net.fabricmc:fabric-loader-junit:${rootProject.fabric_loader_version}"
testImplementation 'org.objenesis:objenesis:3.4'
$fabric_dependencies$
if (!file("${project.rootDir}/src/main/resources/fabric.mod.json").exists()) {
sourceSets.main.resources.srcDirs += "${project.rootDir}/src/main/fabric-resources"
}
} else if (mod_brand == 'forge') {
forge "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}"
forgeRuntimeLibrary project(":$versionlessname$")
$forge_dependencies$
sourceSets.main.resources.srcDirs += "${project.rootDir}/src/main/forge-resources"
} else if (mod_brand == 'neoforge') {
neoForge "net.neoforged:neoforge:${project.neoforge_version}"
forgeRuntimeLibrary project(":$versionlessname$")
$neoforge_dependencies$
sourceSets.main.resources.srcDirs += "${project.rootDir}/src/main/neoforge-resources"
}
// sourceSets.main.java.srcDirs += "${project.rootDir}/UtilityCode/${project.minecraft_version}/src/main/java"
// sourceSets.main.resources.srcDirs += "${project.rootDir}/UtilityCode/${project.minecraft_version}/src/main/resources"
$dependencies$
inc project(":$versionlessname$")
}
if (getFile('dependencies.gradle').exists()) {
apply from: 'dependencies.gradle'
} else if (getFile('dependencies.gradle.kts').exists()) {
apply from: 'dependencies.gradle.kts'
}
shadowJar {
configurations = [project.configurations.inc]
relocate 'dev.tr7zw.util', '$relocationpackage$.util'
relocate 'dev.tr7zw.config', '$relocationpackage$.config'
}
remapJar {
dependsOn(shadowJar)
input = shadowJar.archiveFile
doLast {
// Delete the shadowJar.archiveFile after remapJar task is executed
delete shadowJar.archiveFile
}
if(mcVersion < 11800) {
finalizedBy("java8Jar")
} else if (mcVersion <= 12004) {
finalizedBy("java17Jar")
}
}
test.onlyIf { mod_brand == 'fabric' && mcVersion >= 11800 }
compileTestJava.onlyIf { mod_brand == 'fabric' && mcVersion >= 11800 }
test {
useJUnitPlatform()
}
processResources {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
def neoforgeVersionRange = project.hasProperty('neo_version_range') ? project.neo_version_range : ''
def neoforgeLoaderVersion = project.hasProperty('loader_version_range_neoforge') ? project.loader_version_range_neoforge : ''
def forgeLoaderVersion = project.hasProperty('loader_version_range_forge') ? project.loader_version_range_forge : ''
def fabricApiName = project.hasProperty('fabric_api_name') ? project.fabric_api_name : ''
def versionsMap = [
10809: 1,
11202: 3,
11500: 5,
11605: 6,
11701: 7,
11802: 8,
11902: 9,
11903: 12,
11904: 13,
12001: 15,
12002: 18,
12003: 21,
12004: 22,
12005: 32,
12006: 32,
12100: 34,
12102: 42,
12103: 42,
12104: 46
]
var replaceProperties = [
minecraft_version : minecraft_version, minecraft_version_range_forge: minecraft_dependency,
minecraft_version_range_neoforge : minecraft_dependency,
minecraft_version_range_fabric: minecraft_dependency,
loader_version_range_neoforge: neoforgeLoaderVersion,
loader_version_range_forge: forgeLoaderVersion,
neo_version_range: neoforgeVersionRange,
fabric_entrypoint : "$fabric_entrypoint$",
fabric_modmenu_entrypoint: "$fabric_modmenu_entrypoint$",
fabric_api_name: fabricApiName,
description : "$description$",
homepage_url : "$homepageUrl$",
sources_url : "$sourcesUrl$",
issues_url : "$issuesUrl$",
license_name: "$licenseName$",
mod_id : "$id$", mod_name: "$name$", version: "$version$${getVersionMetadata()}",
mod_author : "$author$", pack_format_number: versionsMap[mcVersion],
]
inputs.properties replaceProperties
filesMatching(['fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '**/pack.mcmeta']) {
expand replaceProperties + [project: project]
}
from "${project.rootDir}/$licensename$"
if (mod_brand != 'fabric') {
exclude {
it.file.name == 'fabric.mod.json'
}
}
}
sourceSets.each {
def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
it.output.resourcesDir = dir
it.java.destinationDirectory = dir
}
afterEvaluate { project ->
project.tasks.withType(JavaExec).configureEach { task ->
if (task.name.startsWith("runClient")) {
task.doFirst {
def binDir = project.file('bin')
if (binDir.exists()) {
deleteBinDir(binDir)
}
}
}
}
}
archivesBaseName = rootProject.archives_base_name
version = mod_brand + "-" + rootProject.mod_version + "-mc" + project.minecraft_version + getVersionMetadata()
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 {
name = "tr7zw-proxy"
url "https://maven.tr7zw.dev/repository/maven-public/"
}
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
maven {
url "https://cursemaven.com"
}
mavenLocal()
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// remapping the jars later for <= 1.20.4 to Java 17
// remapping the jars later for < 1.18 to Java 8
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
java {
//withSourcesJar()
}
def getVersionMetadata() {
// CI builds only
if (project.hasProperty("build.release")) {
return "" // no tag whatsoever
}
if (grgit != null) {
def head = grgit.head()
def id = head.abbreviatedId
// Flag the build if the build tree is not clean
if (!grgit.status().isClean()) {
id += "-dirty"
println "Changes: " + grgit.status().staged.getAllChanges() + " " + grgit.status().unstaged.getAllChanges()
}
return "+git.${id}"
}
// No tracking information could be found about the build
return "+unknown"
}
// Function to delete bin directory recursively
def deleteBinDir(dir) {
ant.delete(dir: dir, failonerror: false)
}
tasks.register("java8Jar", DowngradeJarTask) {
dependsOn remapJar
input = tasks.remapJar.archiveFile.get().asFile
outputSuffix = "+java8"
compileClassPath = sourceSets.main.compileClasspath
copyRuntimeClasses = false
doLast {
// Delete the remapJar.archiveFile
delete remapJar.archiveFile
def inputFile = tasks.remapJar.archiveFile.get().asFile
def outputDirectory = inputFile.parent
def originalFileName = inputFile.getName().substring(0, inputFile.getName().length() - 4);
// Renaming the generated file to the original name
def generatedFile = new File(outputDirectory, "${originalFileName}+java8.jar")
generatedFile.renameTo(inputFile)
}
}
tasks.register("java17Jar", DowngradeJarTask) {
dependsOn remapJar
input = tasks.remapJar.archiveFile.get().asFile
outputSuffix = "+java17"
compileClassPath = sourceSets.main.compileClasspath
copyRuntimeClasses = false
targetVersion = Opcodes.V17
doLast {
// Delete the remapJar.archiveFile
delete remapJar.archiveFile
def inputFile = tasks.remapJar.archiveFile.get().asFile
def outputDirectory = inputFile.parent
def originalFileName = inputFile.getName().substring(0, inputFile.getName().length() - 4);
// Renaming the generated file to the original name
def generatedFile = new File(outputDirectory, "${originalFileName}+java17.jar")
generatedFile.renameTo(inputFile)
}
}
def getFile(String relativePath) {
return new File(projectDir, relativePath)
}