-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
352 lines (317 loc) · 12.9 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
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
plugins {
// TODO for reproducible builds and general toolchain safety, we should really pin to specific versions instead of using SNAPSHOT etc
// see https://github.com/fractureiser-investigation/fractureiser/blob/94f35c5343732b4bf97124ce1cad5744e4ee3602/docs/2023-06-08-meeting.md#discussion-and-action-items-1
id("fabric-loom") version "1.6-SNAPSHOT" apply(false)
id("net.neoforged.gradle.userdev") version "7.0.145" apply(false)
id("org.spongepowered.gradle.vanilla") version "0.2.1-SNAPSHOT" apply(false)
id("org.spongepowered.mixin") version "0.7-SNAPSHOT" apply(false) // TODO now that NF uses fabric mixin do we still need this?
// Publishing
id("com.modrinth.minotaur") version "2.+" apply(false)
id("net.darkhax.curseforgegradle") version "1.1.15" apply(false)
// Environment variables (API keys)
id("co.uzzu.dotenv.gradle") version "2.0.0"
// Reproducible builds
id("reproducible-builds") apply(false)
}
allprojects {
apply plugin: "reproducible-builds"
}
subprojects {
if (project.parent?.parent == rootProject) {
apply plugin: 'java'
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
java.withSourcesJar()
jar {
from(project.parent.file("LICENSE")) {
rename { "${it}_${mod_name}" }
}
}
sourcesJar {
from(project.parent.file("LICENSE")) {
rename { "${it}_${mod_name}" }
}
}
repositories {
mavenCentral()
maven {
name = 'Sponge / Mixin'
url = 'https://repo.spongepowered.org/repository/maven-public/'
}
maven {
name = 'BlameJared Maven (JEI / CraftTweaker / Bookshelf)'
url = 'https://maven.blamejared.com'
}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
it.options.getRelease().set(21)
}
processResources {
filesMatching(['pack.mcmeta', 'fabric.mod.json', '*.mixins.json']) {
expand project.properties
}
}
// Disables Gradle's custom module metadata from being published to maven. The
// metadata includes mapped dependencies which are not reasonably consumable by
// other mod developers.
tasks.withType(GenerateModuleMetadata).configureEach {
enabled = false
}
// `switch` didn't seem to work, so we use chained `if` instead
// TODO this is pretty messy, can we separate them into separate files in the root directory or something?
if (project.name == "common") {
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.gradle.vanilla'
base {
archivesName = "${mod_name}-common-${minecraft_version}-${mod_version}"
}
minecraft {
version(minecraft_version)
if(file("src/main/resources/${mod_id}.accesswidener").exists()){
accessWideners(file("src/main/resources/${mod_id}.accesswidener"))
}
}
dependencies {
compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5'
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.6"))
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
}
} else if (project.name == "fabric") {
var curseProjectId = null;
var modrinthProjectId = null;
if (project.hasProperty("curseforge_id_fabric")) {
curseProjectId = "${project.curseforge_id_fabric}".toString();
} else if (project.hasProperty("curseforge_id")) {
curseProjectId = "${project.curseforge_id}".toString();
}
if (project.hasProperty("modrinth_id")) {
modrinthProjectId = "${project.modrinth_id}".toString();
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'fabric-loom'
if (modrinthProjectId != null) apply plugin: "com.modrinth.minotaur"
if (curseProjectId != null) apply plugin: "net.darkhax.curseforgegradle"
base {
archivesName = "${mod_name}-fabric-${minecraft_version}-${mod_version}"
}
dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
implementation project.parent.childProjects.get("common")
}
loom {
if (project.parent.childProjects.get("common").file("src/main/resources/${mod_id}.accesswidener").exists()) {
accessWidenerPath.set(project.parent.childProjects.get("common").file("src/main/resources/${mod_id}.accesswidener"))
}
mixin {
defaultRefmapName.set("${mod_id}.refmap.json")
}
runs {
client {
client()
setConfigName("Fabric Client")
ideConfigGenerated(true)
runDir("run")
}
server {
server()
setConfigName("Fabric Server")
ideConfigGenerated(true)
runDir("run")
}
}
}
tasks.withType(JavaCompile).configureEach {
source(project.parent.childProjects.get("common").sourceSets.main.allSource)
}
tasks.named("sourcesJar", Jar) {
from(project.parent.childProjects.get("common").sourceSets.main.allSource)
}
processResources {
from project.parent.childProjects.get("common").sourceSets.main.resources
}
if (curseProjectId != null) {
task publishCurseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
group = "publishing"
apiToken = env.CURSEFORGE_TOKEN.value
// debugMode = true
// A project ID is required to tell CurseForge which project the uploaded
// file belongs to. This is public on your project page and is not private
// information.
var projectId = curseProjectId
// Tells CurseForgeGradle to publish the output of the jar task. This will
// return a UploadArtifact object that can be used to further configure the
// file.
def mainFile = upload(projectId, remapJar)
mainFile.changelogType = "markdown"
mainFile.changelog = project.parent.file("changelog.md")
mainFile.releaseType = "${mod_version}".startsWith("0") ? "beta" : "release"
mainFile.displayName = "${display_mc_version}-${mod_version}-fabric"
mainFile.addRequirement("fabric-api")
}
}
if (modrinthProjectId != null) {
modrinth {
token = env.MODRINTH_TOKEN.value
// debugMode = true
projectId = modrinthProjectId
versionNumber = project.mod_version
versionName = "${display_mc_version}-${mod_version}-fabric"
versionType = "${mod_version}".startsWith("0") ? "beta" : "release"
uploadFile = remapJar
gameVersions = [minecraft_version] //modrinthMcVersions == null ? [minecraft_version] : modrinthMcVersions.split(";").map {it.trim()}
dependencies {
required.project "fabric-api"
}
changelog = project.parent.file("changelog.md").text
syncBodyFrom = project.parent.file("README.md").text
}
}
} else if (project.name.endsWith("forge")) {
var curseProjectId = null;
var modrinthProjectId = null;
if (project.hasProperty("curseforge_id_forge")) {
curseProjectId = "${project.curseforge_id_forge}".toString();
} else if (project.hasProperty("curseforge_id")) {
curseProjectId = "${project.curseforge_id}".toString();
}
if (project.hasProperty("modrinth_id")) {
modrinthProjectId = "${project.modrinth_id}".toString()
}
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'net.neoforged.gradle.userdev'
// apply plugin: 'org.spongepowered.mixin' // TODO is this necessary?
if (modrinthProjectId != null) apply plugin: "com.modrinth.minotaur"
if (curseProjectId != null) apply plugin: "net.darkhax.curseforgegradle"
base {
archivesName = "${mod_name}-neoforge-${minecraft_version}-${mod_version}"
}
test.enabled = false // somehow the test task that was never configured anywhere is breaking things?? idk
// FIXME how do we configure mixins on neoforge?
// mixin {
// add(sourceSets.main, "${mod_id}.refmap.json")
//
// config("${mod_id}.mixins.json")
// if (file("src/main/resources/${mod_id}.forge.mixins.json").exists()) {
// config("${mod_id}.forge.mixins.json")
// }
// }
// minecraft {
// mappings channel: 'official', version: minecraft_version
//
// FIXME ATs?
// // Automatically enable forge AccessTransformers if the file exists
// // This location is hardcoded in Forge and can not be changed.
// // https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123
// if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) {
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// }
runs {
client {
workingDirectory project.file('run')
// ideaModule "${rootProject.name}.${project.parent.name}.${project.name}.main"
// taskName 'Client'
systemProperty 'mixin.env.remapRefMap', 'true'
systemProperty 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
// mods {
// modClientRun {
// source sourceSets.main
// source project.parent.childProjects.get("common").sourceSets.main
// }
// }
}
server {
workingDirectory project.file('run')
// ideaModule "${rootProject.name}.${project.parent.name}.${project.name}.main"
// taskName 'Server'
systemProperty 'mixin.env.remapRefMap', 'true'
systemProperty 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
// mods {
// modServerRun {
// source sourceSets.main
// source project.parent.childProjects.get("common").sourceSets.main
// }
// }
}
data {
workingDirectory project.file('run')
// ideaModule "${rootProject.name}.${project.parent.name}.${project.name}.main"
// args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
// taskName 'Data'
systemProperty 'mixin.env.remapRefMap', 'true'
systemProperty 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
// mods {
// modDataRun {
// source sourceSets.main
// source project.parent.childProjects.get("common").sourceSets.main
// }
// }
}
}
// }
sourceSets.main.resources.srcDir 'src/generated/resources'
dependencies {
implementation "net.neoforged:neoforge:${forge_version}"
compileOnly project.parent.childProjects.get("common")
}
tasks.withType(JavaCompile).configureEach {
source(project.parent.childProjects.get("common").sourceSets.main.allSource)
}
tasks.named("sourcesJar", Jar) {
from(project.parent.childProjects.get("common").sourceSets.main.allSource)
}
processResources {
from project.parent.childProjects.get("common").sourceSets.main.resources
// Doing this here instead of earlier on fixes `neoforge.mods.toml` not getting processed properly, for some reason
// TODO is this still necessary?
filesMatching(['META-INF/neoforge.mods.toml']) {
expand project.properties
}
}
if (curseProjectId != null) {
task publishCurseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
group = "publishing"
apiToken = env.CURSEFORGE_TOKEN.value
// debugMode = true
// A project ID is required to tell CurseForge which project the uploaded
// file belongs to. This is public on your project page and is not private
// information.
var projectId = curseProjectId
// Tells CurseForgeGradle to publish the output of the jar task. This will
// return a UploadArtifact object that can be used to further configure the
// file.
def mainFile = upload(projectId, jar)
mainFile.changelogType = "markdown"
mainFile.changelog = project.parent.file("changelog.md")
mainFile.releaseType = "${mod_version}".startsWith("0") ? "beta" : "release"
mainFile.displayName = "${display_mc_version}-${mod_version}-neoforge"
}
}
if (modrinthProjectId != null) {
modrinth {
token = env.MODRINTH_TOKEN.value
// debugMode = true
projectId = modrinthProjectId
versionNumber = project.mod_version
versionName = "${display_mc_version}-${mod_version}-neoforge"
versionType = "${mod_version}".startsWith("0") ? "beta" : "release"
uploadFile = jar
gameVersions = [minecraft_version] //modrinthMcVersions == null ? [minecraft_version] : modrinthMcVersions.split(";").map {it.trim()}
dependencies {
}
changelog = project.parent.file("changelog.md").text
}
}
} else {
logger.warn("Unknown subproject ${project.name} in project ${project.parent.name}")
}
}
}