-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathbuild.gradle
373 lines (325 loc) · 12.8 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
plugins {
id 'java-library'
id 'idea'
id 'maven-publish'
id 'net.neoforged.moddev' version '1.0.14'
id "org.sonarqube" version "5.0.0.4638"
id "net.darkhax.curseforgegradle" version "1.1.15"
id "com.modrinth.minotaur" version "2.+"
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
if (findProject(':SophisticatedCore') != null) {
evaluationDependsOn(':SophisticatedCore')
}
version = "${project.minecraft_version}-${project.mod_version}.${getBuildNumber()}${getStable()}"
group = mod_group_id
repositories {
mavenCentral()
maven { url "https://maven.tterrag.com/" }
maven { url = "https://modmaven.dev/" }
maven { url "https://minecraft.curseforge.com/api/maven/" }
maven {
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven { url "https://maven.blamejared.com/" }
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/p3pp3rf1y/sophisticatedcore")
credentials {
username = System.getenv("USERNAME")
password = System.getenv("READ_PACKAGES_TOKEN")
}
content {
includeGroupByRegex "sophisticatedcore.*"
}
}
}
base {
archivesName = mod_id
}
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
neoForge {
version = project.neo_version
parchment {
mappingsVersion = project.parchment_mappings_version
minecraftVersion = project.parchment_minecraft_version
}
accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')
runs {
configureEach {
systemProperty 'forge.logging.markers', 'REGISTRIES'
systemProperty 'forge.logging.console.level', 'debug'
systemProperty 'mixin.env.disableRefMap', 'true'
}
client {
client()
}
client2 {
client()
programArguments.addAll '--username', 'Dev2'
}
server {
server()
programArgument '--nogui'
}
data {
data()
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
}
mods {
"${mod_id}" {
sourceSet(sourceSets.main)
}
if (findProject(':SophisticatedCore') != null) {
"sophisticatedcore" {
sourceSet(project(':SophisticatedCore').sourceSets.main)
}
}
}
}
sourceSets.main.resources {
srcDir 'src/generated/resources'
}
configurations {
runtimeClasspath.extendsFrom localRuntime
}
dependencies {
if (findProject(':SophisticatedCore') != null) {
dependencies.implementation project(':SophisticatedCore')
} else {
dependencies.implementation("sophisticatedcore:sophisticatedcore:${sc_version}") {
transitive = false
}
dependencies.testImplementation("sophisticatedcore:sophisticatedcore:${sc_version}") {
transitive = false
}
}
// implementation files('/libs/sophisticatedcore-1.20.4-0.6.18.-SNAPSHOT.jar')
compileOnly "mezz.jei:jei-${jei_mc_version}:${jei_version}"
localRuntime "mezz.jei:jei-${jei_mc_version}:${jei_version}"
compileOnly "curse.maven:curios-1037991:${curios_cf_file_id}"
localRuntime "curse.maven:curios-1037991:${curios_cf_file_id}"
compileOnly "curse.maven:balm-531761:${balm_cf_file_id}"
localRuntime "curse.maven:balm-531761:${balm_cf_file_id}"
compileOnly "curse.maven:craftingtweaks-233071:${crafting_tweaks_cf_file_id}"
localRuntime "curse.maven:craftingtweaks-233071:${crafting_tweaks_cf_file_id}"
compileOnly "curse.maven:chipped-456956:${chipped_cf_file_id}"
localRuntime "curse.maven:chipped-456956:${chipped_cf_file_id}"
compileOnly "curse.maven:athena-841890:${athena_cf_file_id}"
localRuntime "curse.maven:athena-841890:${athena_cf_file_id}"
compileOnly "curse.maven:resourcefullib-570073:${resourcefullib_cf_file_id}"
localRuntime "curse.maven:resourcefullib-570073:${resourcefullib_cf_file_id}"
/*
compileOnly "vazkii.botania:Botania:${botania_version}:api")
runtimeOnly "vazkii.botania:Botania:${botania_version}")
compileOnly "vazkii.patchouli:Patchouli:${patchouli_version}:api")
runtimeOnly "vazkii.patchouli:Patchouli:${patchouli_version}")
*/
}
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range,
neo_version : neo_version, neo_version_range: neo_version_range,
loader_version_range: loader_version_range,
mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
mod_issue_tracker_url: mod_issue_tracker_url, mod_logo_file: mod_logo_file, mod_credits: mod_credits,
mod_authors : mod_authors, mod_description: mod_description, mod_display_url: mod_display_url,
mod_full_version : "${project.mod_version}.${getBuildNumber()}${getStable()}",
sc_version :"[" + sc_version.substring(sc_version.indexOf("-") + 1, sc_version.lastIndexOf(',')) + ",)"
]
inputs.properties replaceProperties
expand replaceProperties
from "src/main/templates"
into "build/generated/sources/modMetadata"
}
// Include the output of "generateModMetadata" as an input directory for the build
// this works with both building through Gradle and the IDE.
sourceSets.main.resources.srcDir generateModMetadata
// To avoid having to run "generateModMetadata" manually, make it run on every project reload
neoForge.ideSyncTask generateModMetadata
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
jar {
manifest {
attributes(["Specification-Title" : project.mod_id,
"Specification-Vendor" : project.mod_id,
"Specification-Version" : "1",
"Implementation-Title" : project.name,
"Implementation-Version" : "${version}",
"Implementation-Vendor" : project.mod_id,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")],)
}
}
static def getBuildNumber() {
if (System.getenv("GITHUB_RUN_NUMBER") != null) {
return System.getenv("GITHUB_RUN_NUMBER").toString()
}
return ""
}
static def getStable() {
if (System.getenv("GITHUB_REF") == null || System.getenv("GITHUB_REF").endsWith("-dev")) {
return "-SNAPSHOT"
}
return ""
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("${github_package_url}")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
gpr(MavenPublication) {
artifactId = mod_id
from(components.java)
}
}
}
sonarqube {
properties {
property "sonar.projectName", "${mod_id}"
property "sonar.projectKey", "${sonar_project_key}"
}
}
task generateChangelog {
doLast {
def changelog = new StringBuilder()
// Function to remove characters with Unicode code points 129 or higher
def removeHighUnicodeChars = { text ->
text.codePoints()
.filter { codePoint -> codePoint <= 0x007F } // Keep only ASCII characters (U+0000 to U+007F)
.collect { codePoint -> new String(Character.toChars(codePoint)) }
.join('')
}
// Function to format commit messages with nesting
def formatMultilineMessage = { message ->
// Split message by lines, trim whitespace, and create formatted list
def lines = message.split('\n')
def formattedMessage = lines[0].trim() // First line as top-level list item
if (lines.size() > 1) {
formattedMessage += "\n" + lines[1..-1].collect { line ->
// Trim the line and remove leading dash if present
def trimmedLine = line.trim()
if (trimmedLine.startsWith('-')) {
trimmedLine = trimmedLine.substring(1).trim()
}
" - ${trimmedLine}" // Nested list for additional lines
}.join('\n')
}
return formattedMessage
}
// Function to remove [DEV] section from commit message
def removeDevSection = { message ->
def devIndex = message.indexOf('[DEV]')
if (devIndex != -1) {
return message.substring(0, devIndex).trim()
}
return message
}
// Get the latest commit hash
def latestCommitHash = "git rev-parse HEAD".execute().text.trim()
// Check if the latest commit is a merge commit
def parentCommits = "git rev-list --parents -n 1 ${latestCommitHash}".execute().text.split()
logger.info("Parent commits: ${parentCommits}")
def commitMessages = []
if (parentCommits.size() > 2) { // Merge commit has more than 2 parents
def firstParent = parentCommits[1]
def secondParent = parentCommits[2]
def gitLogCommand = [
"bash", "-c", "git log --pretty=format:%B ${firstParent}..${secondParent}"
]
commitMessages = gitLogCommand.execute().text.split('\n\n') // Split by two newlines for each commit
logger.info("Merge commit, ran git log command: ${gitLogCommand.join(' ')} and got ${commitMessages}")
} else {
// Single commit log
commitMessages = "git log -1 --pretty=%B".execute().text.split('\n\n')
// Split by two newlines for each commit
logger.info("Single commit, ran git log command: git log -1 --pretty=%B and got ${commitMessages}");
}
def features = []
def fixes = []
commitMessages.each { commitMessage ->
commitMessage = removeHighUnicodeChars(commitMessage) // Remove high Unicode characters
commitMessage = removeDevSection(commitMessage) // Remove [DEV] section
if (commitMessage.startsWith('feat: ')) {
features.add(commitMessage.replaceFirst('feat: ', '').trim())
} else if (commitMessage.startsWith('fix: ')) {
fixes.add(commitMessage.replaceFirst('fix: ', '').trim())
}
}
if (features) {
changelog.append("### Features\n")
features.each { feature -> changelog.append("- ${formatMultilineMessage(feature)}\n") }
}
if (fixes) {
changelog.append("### Fixes\n")
fixes.each { fix -> changelog.append("- ${formatMultilineMessage(fix)}\n") }
}
// Store the changelog in a project property or an environment variable
logger.info("Compiled changelog: " + changelog.toString())
project.ext.changelog = changelog.toString()
}
project.ext.changelog = ""
}
task curseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
dependsOn 'generateChangelog'
apiToken = System.getenv("CURSEFORGE_TOKEN")
def mainFile = upload(project.curseforge_id, file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"))
mainFile.changelogType = 'markdown'
mainFile.changelog = {project.ext.changelog}
mainFile.addModLoader('NeoForge')
mainFile.releaseType = "${release_type}"
"${release_versions}".split(',').each {
mainFile.addGameVersion("${it}")
}
mainFile.addRequirement('sophisticated-core')
mainFile.addOptional('jei')
mainFile.addOptional('curios-continuation')
mainFile.addOptional('crafting-tweaks')
onlyIf { !project.ext.changelog.isEmpty() }
}
modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = "${modrinth_project_id}"
versionType = "${release_type}"
uploadFile = jar
gameVersions = "${release_versions}".split(',').collect {e -> e}
loaders = ["neoforge"]
dependencies {
required.project "sophisticated-core"
optional.project "jei"
optional.project "crafting-tweaks"
optional.project "curios-continuation"
}
changelog = provider {
project.ext.changelog
}
}
tasks.modrinth {
dependsOn(tasks.generateChangelog)
onlyIf { !project.ext.changelog.isEmpty() }
}
task printVersionName {
println "version:" + project.version
}