-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
445 lines (403 loc) · 17.1 KB
/
Copy pathbuild.gradle
File metadata and controls
445 lines (403 loc) · 17.1 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
plugins {
id 'fabric-loom' version "${loom_version}"
id 'jacoco'
}
jacoco {
toolVersion = '0.8.12'
}
version = computeModVersion()
group = project.maven_group
tasks.register('printVersion') {
doLast { println project.version }
}
// Derives a SemVer-compliant version from `mod_version` plus the git state:
// - exact tag match (e.g. HEAD == v0.0.0) → "0.0.0"
// - exact tag, dirty tree → "0.0.0+dirty"
// - N commits past the last matching tag → "0.0.0+N.gSHA[.dirty]"
// - no matching tag yet → "0.0.0+gSHA[.dirty]"
// - git unavailable or describe fails → "0.0.0"
// The base ("0.0.0") comes from gradle.properties and is bumped via
// scripts/release.sh. Tag pattern is `v*`.
def computeModVersion() {
def base = project.mod_version
def tagPrefix = "v"
def described = runGitDescribe(tagPrefix)
if (described == null || described.isEmpty()) {
return base
}
if (described == "${tagPrefix}${base}") {
return base
}
if (described == "${tagPrefix}${base}-dirty") {
return "${base}+dirty"
}
def postTag = described =~ /^\Q${tagPrefix}\E(\S+?)-(\d+)-g([0-9a-f]+)(-dirty)?$/
if (postTag.matches()) {
def commits = postTag[0][2]
def sha = postTag[0][3]
def dirty = postTag[0][4] ? '.dirty' : ''
return "${base}+${commits}.g${sha}${dirty}"
}
def shaOnly = described =~ /^([0-9a-f]+)(-dirty)?$/
if (shaOnly.matches()) {
def sha = shaOnly[0][1]
def dirty = shaOnly[0][2] ? '.dirty' : ''
return "${base}+g${sha}${dirty}"
}
return base
}
def runGitDescribe(String tagPrefix) {
try {
def proc = new ProcessBuilder('git', 'describe', '--tags',
'--match', "${tagPrefix}*", '--dirty', '--always')
.directory(rootDir)
.redirectErrorStream(true)
.start()
proc.waitFor()
def out = proc.inputStream.text.trim()
if (proc.exitValue() != 0) return null
return out
} catch (Exception ignored) {
return null
}
}
repositories {
mavenCentral()
maven {
name = 'TerraformersMC'
url = 'https://maven.terraformersmc.com/'
content {
includeGroup 'dev.emi'
}
}
maven {
name = 'Shedaniel'
url = 'https://maven.shedaniel.me/'
content {
includeGroup 'me.shedaniel'
includeGroup 'me.shedaniel.cloth'
includeGroup 'dev.architectury'
}
}
maven {
name = 'Architectury'
url = 'https://maven.architectury.dev/'
content {
includeGroup 'dev.architectury'
}
}
maven {
name = 'BlameJared'
url = 'https://maven.blamejared.com/'
content {
includeGroup 'mezz.jei'
}
}
maven {
name = 'Modrinth'
url = 'https://api.modrinth.com/maven'
content {
includeGroup 'maven.modrinth'
}
}
// GitHub Releases — resolves sibling Concord mods straight from their release jars while
// their Modrinth projects are not publicly resolvable. Artifact-only (no metadata), scoped
// to the rfizzle org so it never shadows a real Maven group.
ivy {
name = 'GitHubReleases'
url = 'https://github.com'
patternLayout {
artifact '/[organisation]/[module]/releases/download/v[revision]/[module]-[revision].jar'
}
metadataSources {
artifact()
}
content {
includeGroup 'rfizzle'
}
}
maven {
name = 'Bai'
url = 'https://maven2.bai.lol'
content {
includeGroup 'lol.bai'
includeGroup 'mcp.mobius.waila'
}
}
maven {
name = 'FTB'
url = 'https://maven.ftb.dev/releases'
content {
includeGroup 'dev.ftb.mods'
}
}
}
loom {
splitEnvironmentSourceSets()
}
sourceSets {
main {
resources {
srcDirs += [ "src/main/generated" ]
}
}
gametest {
compileClasspath += sourceSets.main.compileClasspath + sourceSets.main.output
runtimeClasspath += sourceSets.main.runtimeClasspath + sourceSets.main.output
}
}
configurations {
gametestImplementation.extendsFrom implementation
gametestRuntimeOnly.extendsFrom runtimeOnly
}
// Minecraft's GameTestServer aborts ("No test functions were given!") when zero @GameTest
// functions are registered, so runGametest would fail CI until the first gametest lands.
// Skip the run while the gametest source set is empty; it runs normally once tests exist.
// Loom registers runGametest during afterEvaluate, so match it lazily rather than by name.
tasks.matching { it.name == 'runGametest' }.configureEach {
onlyIf {
!sourceSets.gametest.allJava.files.isEmpty()
}
}
loom {
runs {
datagen {
inherit server
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}"
vmArg "-Dfabric-api.datagen.modid=prosperity"
runDir "build/datagen"
}
gametest {
server()
name "Game Test"
source sourceSets.gametest
vmArg "-Dfabric-api.gametest"
vmArg "-Dfabric-api.gametest.report-file=${layout.buildDirectory.file('junit-gametest.xml').get().asFile}"
runDir "build/gametest"
}
}
}
dependencies {
// Minecraft
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
// Fabric
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Client source set
"clientImplementation"("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
// ModMenu 11.x — Config screen entry point for Fabric 1.21.1. Compile-only + dev runtime
// so end users get the integration only when they install ModMenu themselves.
modCompileOnly "maven.modrinth:modmenu:${project.modmenu_version}"
modLocalRuntime "maven.modrinth:modmenu:${project.modmenu_version}"
// Cloth Config 15.x — Config screen builder used by ModMenuIntegration. Compile-only for
// the api surface; full mod in dev runtime.
modCompileOnly "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}"
modLocalRuntime "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}"
// Jade 15.x — Probe-tooltip integration. No api split published; compile-only links the
// full mod but only the snownee.jade.api surface is referenced.
modCompileOnly "maven.modrinth:jade:${project.jade_version}"
modLocalRuntime "maven.modrinth:jade:${project.jade_version}"
// WTHIT 12.x — Alternative probe-tooltip integration (Jade fallback). Compile-only against
// the API split. Discovered via waila_plugins.json at runtime.
modCompileOnly "mcp.mobius.waila:wthit-api:${project.wthit_version}"
// EMI 1.x — Recipe viewer loot index panel.
modCompileOnly "dev.emi:emi-fabric:${project.emi_version}:api"
modLocalRuntime "dev.emi:emi-fabric:${project.emi_version}"
// REI 16.x — Recipe viewer loot index panel (MC 1.21, runs on 1.21.1).
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:${project.rei_version}"
modLocalRuntime "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
modLocalRuntime "dev.architectury:architectury-fabric:${project.architectury_version}"
// JEI 19.x — Recipe viewer loot index panel. The `fabric` runtime jar shades in all
// `common-api` classes, so `transitive = false` prevents Loom remap from seeing the
// same classes twice and emitting `duplicate input class` warnings.
modCompileOnly "mezz.jei:jei-1.21.1-fabric-api:${project.jei_version}"
modLocalRuntime("mezz.jei:jei-1.21.1-fabric:${project.jei_version}") {
transitive = false
}
// Tribulation — sibling Concord mod; soft dependency for the difficulty-tier loot bias.
// Compile-only against its api package behind isModLoaded guards, never bundled. Resolved
// from the GitHub release jar (GitHubReleases ivy repo) because the Modrinth project is not
// publicly resolvable; swap to maven.modrinth once it is.
modCompileOnly "rfizzle:tribulation:${project.tribulation_version}"
// Meridian — sibling Concord mod; soft dependency for distance-scaled enchantment rolls on
// injected Meridian books. Compile-only against its api package behind isModLoaded guards,
// never bundled. Resolved from the GitHub release jar (GitHubReleases ivy repo) because the
// Modrinth project is not publicly resolvable; swap to maven.modrinth once it is.
modCompileOnly "rfizzle:meridian:${project.meridian_version}"
// Open Parties and Claims — player-managed party mod; soft dependency for party loot grouping.
// Compile-only against its xaero.pac.common.server.*.api surface behind an isModLoaded guard,
// never bundled and with no dev runtime — with OPAC absent the mod behaves identically.
modCompileOnly "maven.modrinth:open-parties-and-claims:${project.opac_version}"
// FTB Teams — player-managed party mod; soft dependency for party loot grouping. Compile-only
// against its dev.ftb.mods.ftbteams.api surface behind an isModLoaded guard, never bundled and
// with no dev runtime — with FTB Teams absent the mod behaves identically. FTB Library is a
// compile-time transitive (Color4I appears on Team/TeamManager signatures). `transitive = false`
// keeps FTB's own fabric-api/loader/architectury pins from shadowing the versions pinned above.
modCompileOnly("dev.ftb.mods:ftb-teams-fabric:${project.ftb_teams_version}") {
transitive = false
}
modCompileOnly("dev.ftb.mods:ftb-library-fabric:${project.ftb_library_version}") {
transitive = false
}
// Tests
testImplementation platform("org.junit:junit-bom:${project.junit_version}")
testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation "org.junit.jupiter:junit-jupiter-params"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
// Knot-based classloader that boots Fabric before tests run — registries,
// item registrations, and onInitialize are available without Bootstrap.bootStrap().
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
}
// With splitEnvironmentSourceSets, loom remaps fabric-api to *-common variants for the main
// runtime classpath but leaves the unmapped fabric-api sibling on testRuntimeClasspath.
// fabric-loader-junit then reads both the remapped (named) AW and the unmapped (intermediary)
// AW and aborts on namespace mismatch. Dropping the unmapped sibling keeps the remapped
// artifacts in place and lets the junit launcher boot.
configurations.testRuntimeClasspath {
exclude group: 'net.fabricmc.fabric-api', module: 'fabric-api'
}
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
}
}
// Attach the JaCoCo agent to the gametest server so code only exercised in-game
// (interception, indicators, commands, registration) counts toward coverage. Loom's
// run task is a JavaExec, so the task extension applies. The includes filter keeps
// the agent from instrumenting Minecraft/Fabric classes. Matched lazily for the same
// reason as the onlyIf block above — Loom registers runGametest during afterEvaluate.
tasks.matching { it.name == 'runGametest' }.configureEach {
jacoco.applyTo(it)
it.jacoco.destinationFile = layout.buildDirectory.file('jacoco/runGametest.exec').get().asFile
it.jacoco.includes = ['com.rfizzle.prosperity.*']
// The agent's exec file is an @OutputFile, which would otherwise make this
// JavaExec up-to-date-checkable and silently skip the whole in-world suite on
// a repeat run — re-emitting the previous coverage number as if it were fresh.
// A gametest sweep must always execute.
it.outputs.upToDateWhen { false }
}
// Single source of coverage truth: unit tests + gametests merged over src/main.
tasks.register('jacocoMergedReport', JacocoReport) {
description = 'Merged unit-test + gametest coverage report over src/main'
group = 'verification'
// The report reads compileJava/processResources output, so it must depend on
// them — without this, any invocation that compiles without also scheduling a
// test task (e.g. `gradlew jar jacocoMergedReport`) fails Gradle's
// implicit-dependency validation.
dependsOn tasks.named('classes')
// Ordering only — not dependsOn, so the report can run from existing exec
// data without forcing a gametest server spin-up.
mustRunAfter test, 'runGametest'
// fileTree only picks up exec files that exist, so the report still runs when
// one of the two sweeps hasn't.
executionData fileTree(layout.buildDirectory.dir('jacoco')) {
include 'test.exec', 'runGametest.exec'
}
// A sweep that never ran leaves its exec file absent, which would otherwise
// yield a partial number under the "merged" label with no indication.
doFirst {
['test.exec', 'runGametest.exec'].each { name ->
def execFile = layout.buildDirectory.file("jacoco/${name}").get().asFile
if (!execFile.exists() || execFile.length() == 0) {
logger.warn("jacocoMergedReport: ${name} is missing or empty — this report is NOT merged coverage")
}
}
}
sourceSets sourceSets.main
// Mixin bodies execute inside the transformed vanilla classes, so the agent
// can never attribute coverage to the mixin class files — excluding them keeps
// the denominator honest. Mixins stay thin (delegate to handlers) so nothing
// measurable hides here. Deriving from sourceSets.main.output lazily keeps the
// task dependency on `classes` inside the file collection itself, rather than
// resolving eagerly at configuration time.
classDirectories.setFrom(files(sourceSets.main.output).asFileTree.matching {
exclude 'com/rfizzle/prosperity/mixin/**'
})
reports {
xml.required = true
html.required = true
}
}
tasks.register('verifyDatagenIdempotent') {
description = 'Runs datagen and asserts git reports no changes in src/main/generated/'
group = 'verification'
dependsOn 'runDatagen'
notCompatibleWithConfigurationCache('shells out to git against live working-tree state')
doLast {
def genDir = file('src/main/generated').absolutePath
def runGit = { List<String> argv ->
try {
def out = providers.exec {
commandLine argv
ignoreExitValue = true
}
out.result.get() // force resolution so a failure to start lands in the catch
return out
} catch (Exception e) {
throw new GradleException(
'verifyDatagenIdempotent needs git on PATH to inspect ' +
'src/main/generated/, and could not run it: ' + e.message, e)
}
}
def firstLines = { String text ->
def lines = text.trim().readLines()
lines.size() > 5 ? lines.take(5).join('\n') + "\n… (${lines.size()} lines total)"
: lines.join('\n')
}
def statusResult = runGit(['git', 'status', '--porcelain', '--', genDir])
def statusExit = statusResult.result.get().exitValue
if (statusExit != 0) {
throw new GradleException(
"git status failed with exit ${statusExit} while checking src/main/generated/:\n" +
firstLines(statusResult.standardError.asText.get()))
}
def dirty = statusResult.standardOutput.asText.get().trim()
if (!dirty.isEmpty()) {
throw new GradleException(
'src/main/generated/ changed after runDatagen:\n' + firstLines(dirty) +
'\nRun ./gradlew runDatagen, then git add and commit the results.')
}
}
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
exclude "**/.gitkeep"
exclude "**/.cache"
}
processClientResources {
exclude "**/.gitkeep"
exclude "**/.cache"
}
tasks.withType(JavaCompile).configureEach {
it.options.release = project.java_version.toInteger()
}
java {
sourceCompatibility = JavaVersion.toVersion(project.java_version)
targetCompatibility = JavaVersion.toVersion(project.java_version)
withSourcesJar()
}
jar {
from("LICENSE") {
rename { "${it}_${project.archives_base_name}" }
}
exclude "**/.gitkeep"
exclude "**/.cache"
}
tasks.named('sourcesJar') {
exclude "**/.gitkeep"
exclude "**/.cache"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}