Skip to content

Commit 7c1e3f0

Browse files
committed
fix build issues
1 parent 95d43f7 commit 7c1e3f0

3 files changed

Lines changed: 85 additions & 79 deletions

File tree

build.gradle

Lines changed: 81 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ plugins {
55
id 'net.darkhax.curseforgegradle' version "${curseforgegradle_plugin_version}" apply false
66
}
77

8+
ext {
9+
archivesBaseNameFabric = "${archives_base_name}-fabric"
10+
archivesBaseNameNeoForge = "${archives_base_name}-neoforge"
11+
}
12+
813
subprojects {
914
tasks.withType(JavaCompile).configureEach {
1015
it.options.release = project.java_version as Integer
@@ -23,28 +28,28 @@ tasks.register('validateRelease') {
2328
group = 'release'
2429
description = 'Validates that the environment is ready for a release'
2530

26-
doFirst {
27-
if (!System.getenv("CURSEFORGE_TOKEN")) {
28-
throw new GradleException("CURSEFORGE_TOKEN environment variable not set")
29-
}
31+
doFirst {
32+
if (!System.getenv("CURSEFORGE_TOKEN")) {
33+
throw new GradleException("CURSEFORGE_TOKEN environment variable not set")
34+
}
3035
if (!System.getenv("MODRINTH_TOKEN")) {
3136
throw new GradleException("MODRINTH_TOKEN environment variable not set")
3237
}
33-
}
38+
}
3439

3540
doLast {
3641
// Check git status
3742
def gitStatus = 'git status --porcelain'.execute().text.trim()
3843
if (!gitStatus.isEmpty()) {
3944
throw new GradleException("Working directory not clean, cannot release:\n${gitStatus}")
4045
}
41-
46+
4247
// Check branch
4348
def currentBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
4449
if (currentBranch != 'main') {
4550
throw new GradleException("Releases must be performed on main. Currently on '${currentBranch}'")
4651
}
47-
52+
4853
println "✓ Working directory is clean"
4954
println "✓ On main branch"
5055
}
@@ -60,33 +65,33 @@ tasks.register('prepareReleaseVersion') {
6065
doLast {
6166
def propsFile = file('gradle.properties')
6267
def content = propsFile.text
63-
68+
6469
// Extract current version using regex
6570
def matcher = content =~ /(?m)^mod_version\s*=\s*(.+)$/
6671
if (!matcher.find()) {
6772
throw new GradleException("Could not find mod_version in gradle.properties")
6873
}
69-
74+
7075
def currentVersion = matcher.group(1).trim()
7176
println "Current version: ${currentVersion}"
72-
77+
7378
if (!currentVersion.contains('-prerelease')) {
7479
throw new GradleException("Current version is not a prerelease: ${currentVersion}")
7580
}
76-
81+
7782
def releaseVersion = currentVersion.replace('-prerelease', '')
7883
println "Release version: ${releaseVersion}"
79-
84+
8085
// Replace the line in the file, preserving everything else
8186
def updatedContent = content.replaceAll(
8287
/(?m)^mod_version\s*=\s*.+$/,
8388
"mod_version = ${releaseVersion}"
8489
)
85-
90+
8691
propsFile.text = updatedContent
87-
92+
8893
println "✓ Updated gradle.properties to version ${releaseVersion}"
89-
94+
9095
// Store for later tasks
9196
project.ext.releaseVersion = releaseVersion
9297
}
@@ -98,10 +103,10 @@ tasks.register('prepareReleaseVersion') {
98103
tasks.register('commitReleaseVersion') {
99104
group = 'release'
100105
description = 'Commits the release version to git'
101-
106+
102107
doLast {
103108
def releaseVersion = project.ext.releaseVersion
104-
109+
105110
// Stage and commit
106111
def addResult = ["git", "add", "gradle.properties"].execute()
107112
def addOutput = new StringBuilder()
@@ -111,7 +116,7 @@ tasks.register('commitReleaseVersion') {
111116
if (addResult.exitValue() != 0) {
112117
throw new GradleException("Failed to stage gradle.properties: ${addError}")
113118
}
114-
119+
115120
def commitResult = ["git", "commit", "-m", "*** Release ${releaseVersion} ***"].execute()
116121
def commitOutput = new StringBuilder()
117122
def commitError = new StringBuilder()
@@ -120,7 +125,7 @@ tasks.register('commitReleaseVersion') {
120125
if (commitResult.exitValue() != 0) {
121126
throw new GradleException("Failed to commit release version:\n${commitOutput}\n${commitError}")
122127
}
123-
128+
124129
println "✓ Committed release version ${releaseVersion}"
125130
}
126131
}
@@ -132,12 +137,12 @@ tasks.register('commitReleaseVersion') {
132137
tasks.register('buildReleaseJars') {
133138
group = 'release'
134139
description = 'Builds Fabric and NeoForge release jars'
135-
140+
136141
doLast {
137142
def releaseVersion = project.ext.releaseVersion
138-
143+
139144
println "Building release jars with version ${releaseVersion}..."
140-
145+
141146
// Run Gradle as subprocess to pick up updated gradle.properties
142147
// Clean first to remove any cached artifacts with old version
143148
def gradleCmd = [
@@ -147,17 +152,17 @@ tasks.register('buildReleaseJars') {
147152
':neoforge:build',
148153
'--console=plain'
149154
]
150-
155+
151156
def buildProcess = gradleCmd.execute()
152157
buildProcess.waitForProcessOutput(System.out, System.err)
153-
158+
154159
if (buildProcess.exitValue() != 0) {
155160
throw new GradleException("Failed to build release jars")
156161
}
157-
162+
158163
println "✓ Built release jars:"
159-
println " - fabric/build/libs/${project.archives_base_name_fabric}-${releaseVersion}.jar"
160-
println " - neoforge/build/libs/${project.archives_base_name_neoforge}-${releaseVersion}.jar"
164+
println " - fabric/build/libs/${archivesBaseNameFabric}-${releaseVersion}.jar"
165+
println " - neoforge/build/libs/${archivesBaseNameNeoForge}-${releaseVersion}.jar"
161166
}
162167
}
163168

@@ -167,24 +172,24 @@ tasks.register('buildReleaseJars') {
167172
tasks.register('publishGitHub') {
168173
group = 'release'
169174
description = 'Pushes to git and creates GitHub release'
170-
175+
171176
doLast {
172177
def releaseVersion = project.ext.releaseVersion
173-
178+
174179
// Push commits
175180
println "Pushing to origin..."
176181
def pushResult = ["git", "push"].execute()
177182
pushResult.waitForProcessOutput(System.out, System.err)
178183
if (pushResult.exitValue() != 0) {
179184
throw new GradleException("Failed to push to git")
180185
}
181-
186+
182187
// Create GitHub release
183188
println "Creating GitHub release ${releaseVersion}..."
184189
def currentBranch = 'git branch --show-current'.execute().text.trim()
185-
186-
def fabricJar = file("fabric/build/libs/${project.archives_base_name_fabric}-${releaseVersion}.jar")
187-
def neoforgeJar = file("neoforge/build/libs/${project.archives_base_name_neoforge}-${releaseVersion}.jar")
190+
191+
def fabricJar = file("fabric/build/libs/${archivesBaseNameFabric}-${releaseVersion}.jar")
192+
def neoforgeJar = file("neoforge/build/libs/${archivesBaseNameNeoForge}-${releaseVersion}.jar")
188193

189194
if (!fabricJar.exists()) throw new GradleException("Fabric release jar not found at ${fabricJar}")
190195
if (!neoforgeJar.exists()) throw new GradleException("NeoForge release jar not found at ${neoforgeJar}")
@@ -199,13 +204,13 @@ tasks.register('publishGitHub') {
199204
fabricJar.absolutePath,
200205
neoforgeJar.absolutePath
201206
]
202-
207+
203208
def ghResult = ghCmd.execute()
204209
ghResult.waitForProcessOutput(System.out, System.err)
205210
if (ghResult.exitValue() != 0) {
206211
throw new GradleException("Failed to create GitHub release")
207212
}
208-
213+
209214
println "✓ Created GitHub release ${releaseVersion}"
210215
}
211216
}
@@ -253,10 +258,10 @@ tasks.register('publishModrinth') {
253258

254259
def releaseVersion = project.ext.releaseVersion
255260
def gradleCmd = [
256-
'./gradlew',
257-
':fabric:modrinth',
258-
':neoforge:modrinth',
259-
'--console=plain'
261+
'./gradlew',
262+
':fabric:modrinth',
263+
':neoforge:modrinth',
264+
'--console=plain'
260265
]
261266

262267
def publishProcess = gradleCmd.execute()
@@ -276,43 +281,43 @@ tasks.register('publishModrinth') {
276281
tasks.register('bumpVersion') {
277282
group = 'release'
278283
description = 'Increments version and adds -prerelease suffix'
279-
284+
280285
doLast {
281286
def propsFile = file('gradle.properties')
282287
def content = propsFile.text
283-
288+
284289
// Extract current version using regex
285290
def matcher = content =~ /(?m)^mod_version\s*=\s*(.+)$/
286291
if (!matcher.find()) {
287292
throw new GradleException("Could not find mod_version in gradle.properties")
288293
}
289-
294+
290295
def releaseVersion = matcher.group(1).trim()
291296
println "Previous release version: ${releaseVersion}"
292-
297+
293298
// Parse the version: "0.23.0+1.21.10" -> major.minor.patch + buildMetadata
294299
def versionParts = releaseVersion.split('\\+')
295300
def semver = versionParts[0].split('\\.')
296301
def buildMetadata = versionParts.length > 1 ? versionParts[1] : ''
297-
302+
298303
// Increment patch version
299304
def major = semver[0]
300305
def minor = semver[1]
301306
def patch = (semver[2] as Integer) + 1
302-
307+
303308
def nextVersion = "${major}.${minor}.${patch}+${buildMetadata}-prerelease"
304309
println "Next version: ${nextVersion}"
305-
310+
306311
// Replace the line in the file, preserving everything else
307312
def updatedContent = content.replaceAll(
308313
/(?m)^mod_version\s*=\s*.+$/,
309314
"mod_version = ${nextVersion}"
310315
)
311-
316+
312317
propsFile.text = updatedContent
313-
318+
314319
println "✓ Updated gradle.properties to version ${nextVersion}"
315-
320+
316321
// Store for later tasks
317322
project.ext.nextVersion = nextVersion
318323
}
@@ -324,10 +329,10 @@ tasks.register('bumpVersion') {
324329
tasks.register('commitVersionBump') {
325330
group = 'release'
326331
description = 'Commits and pushes the version bump'
327-
332+
328333
doLast {
329334
def nextVersion = project.ext.nextVersion
330-
335+
331336
// Commit and push
332337
def addResult = ["git", "add", "gradle.properties"].execute()
333338
def addOutput = new StringBuilder()
@@ -337,7 +342,7 @@ tasks.register('commitVersionBump') {
337342
if (addResult.exitValue() != 0) {
338343
throw new GradleException("Failed to stage gradle.properties: ${addError}")
339344
}
340-
345+
341346
def commitResult = ["git", "commit", "-m", "Prepare for next version ${nextVersion}"].execute()
342347
def commitOutput = new StringBuilder()
343348
def commitError = new StringBuilder()
@@ -346,46 +351,46 @@ tasks.register('commitVersionBump') {
346351
if (commitResult.exitValue() != 0) {
347352
throw new GradleException("Failed to commit version bump:\n${commitOutput}\n${commitError}")
348353
}
349-
354+
350355
def pushResult = ["git", "push"].execute()
351356
pushResult.waitForProcessOutput(System.out, System.err)
352357
if (pushResult.exitValue() != 0) {
353358
throw new GradleException("Failed to push version bump")
354359
}
355-
360+
356361
println "✓ Committed and pushed version bump to ${nextVersion}"
357362
}
358363
}
359364

360365
/**
361366
* Complete release workflow
362-
*
367+
*
363368
* Executes tasks in this order:
364-
* 1. validateRelease - Check git status
369+
* 1. validateRelease - Check git status
365370
* 2. prepareReleaseVersion - Remove -prerelease suffix
366-
* 3. commitReleaseVersion - Commit version change
367-
* 4. buildReleaseJars - Build both loaders
368-
* 5. publishGitHub - Push and create GitHub release
369-
* 6. publishCurseForge - Publish to CurseForge
370-
* 7. publishModrinth - Publish to Modrinth
371-
* 8. bumpVersion - Increment version, add -prerelease
372-
* 9. commitVersionBump - Commit and push next version
371+
* 3. commitReleaseVersion - Commit version change
372+
* 4. buildReleaseJars - Build both loaders
373+
* 5. publishGitHub - Push and create GitHub release
374+
* 6. publishCurseForge - Publish to CurseForge
375+
* 7. publishModrinth - Publish to Modrinth
376+
* 8. bumpVersion - Increment version, add -prerelease
377+
* 9. commitVersionBump - Commit and push next version
373378
*/
374379
tasks.register('release') {
375380
group = 'release'
376381
description = 'Complete release: GitHub, CurseForge, Modrinth, and version bump'
377-
382+
378383
// All tasks that need to run
379-
dependsOn validateRelease,
380-
prepareReleaseVersion,
381-
commitReleaseVersion,
382-
buildReleaseJars,
383-
publishGitHub,
384-
publishCurseForge,
385-
publishModrinth,
386-
bumpVersion,
384+
dependsOn validateRelease,
385+
prepareReleaseVersion,
386+
commitReleaseVersion,
387+
buildReleaseJars,
388+
publishGitHub,
389+
publishCurseForge,
390+
publishModrinth,
391+
bumpVersion,
387392
commitVersionBump
388-
393+
389394
// Execution order
390395
prepareReleaseVersion.mustRunAfter validateRelease
391396
commitReleaseVersion.mustRunAfter prepareReleaseVersion
@@ -395,15 +400,15 @@ tasks.register('release') {
395400
publishModrinth.mustRunAfter publishCurseForge
396401
bumpVersion.mustRunAfter publishModrinth
397402
commitVersionBump.mustRunAfter bumpVersion
398-
403+
399404
doFirst {
400405
println ""
401406
println "╔════════════════════════════════════════════════════════════╗"
402407
println "║ Starting Release Process ║"
403408
println "╚════════════════════════════════════════════════════════════╝"
404409
println ""
405410
}
406-
411+
407412
doLast {
408413
println ""
409414
println "╔════════════════════════════════════════════════════════════╗"
@@ -412,3 +417,4 @@ tasks.register('release') {
412417
println ""
413418
}
414419
}
420+

0 commit comments

Comments
 (0)