-
Notifications
You must be signed in to change notification settings - Fork 45
/
build.gradle
325 lines (278 loc) · 7.98 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
plugins {
id 'org.quiltmc.loom' version '1.2.+'
id 'org.quiltmc.gradle.licenser' version '2.0.+'
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.modrinth.minotaur' version '2.+'
id 'com.matthewprenger.cursegradle' version '1.4.+'
}
import com.modrinth.minotaur.dependencies.ModDependency
group = project.maven_group
version = "${project.mod_version}+${project.minecraft_version}"
archivesBaseName = project.archives_base_name
Set<String[]> modules = [
["core", "crash_info"],
["core", "lifecycle_events"],
["core", "resource_loader"],
["block", "block_extensions"],
["gui", "screen"],
["gui", "tooltip"]
]
Set<String> fabricModules = [
'fabric-model-loading-api-v1',
'fabric-renderer-api-v1',
'fabric-renderer-indigo'
]
Set<String> runtimeModules = [
'fabric-lifecycle-events-v1',
'fabric-key-binding-api-v1',
'fabric-rendering-v1',
'fabric-resource-loader-v0',
'fabric-screen-api-v1'
]
// This field defines the Java version your mod target.
def targetJavaVersion = 17
boolean isMCVersionNonRelease() {
return project.minecraft_version.matches('^\\d\\dw\\d\\d[a-z]$')
|| project.minecraft_version.matches('\\d+\\.\\d+-(pre|rc)(\\d+)')
}
String getMCVersionString() {
if (isMCVersionNonRelease()) {
return project.minecraft_version
}
def version = project.minecraft_version.split('\\.')
return version[0] + '.' + version[1]
}
String getVersionType() {
if (isMCVersionNonRelease() || version.contains("-alpha.")) {
return "alpha"
} else if (version.contains("-beta.")) {
return "beta"
} else {
return "release"
}
}
String parseReadme() {
def linkRegex = /!\[([A-z._ ]+)]\((images\/[A-z.\/_]+)\)/
def readme = (String) file('README.md').text
def lines = new ArrayList<>(Arrays.asList(readme.split("\n")))
def it = lines.iterator()
boolean shouldRemove = false;
while (it.hasNext()) {
def line = it.next();
if (line.equals("<!-- modrinth_exclude.long_start -->")) {
shouldRemove = true
}
if (shouldRemove) {
it.remove()
}
if (line.equals("<!-- modrinth_exclude.long_end -->")) {
shouldRemove = false
}
}
readme = lines.join("\n")
readme = readme.replaceAll(linkRegex, '![$1](https://raw.githubusercontent.com/LambdAurora/LambdaBetterGrass/1.20/$2)')
return readme
}
String fetchChangelog() {
def changelogText = file('CHANGELOG.md').text
def regexVersion = ((String) project.mod_version).replaceAll('\\.', /\\./).replaceAll('\\+', '\\+')
def changelogRegex = ~"###? ${regexVersion}\\n\\n(( *- .+\\n)+)"
def matcher = changelogText =~ changelogRegex
if (matcher.find()) {
def changelogContent = matcher.group(1)
def changelogLines = changelogText.split('\n')
def linkRefRegex = ~'^\\[([A-z\\d _\\-/+.]+)]: '
for (int i = changelogLines.length - 1; i > 0; i--) {
def line = changelogLines[i]
if ((line =~ linkRefRegex).find())
changelogContent += '\n' + line
else break
}
return changelogContent
} else {
return null;
}
}
repositories {
mavenLocal()
mavenCentral()
maven {
name 'Gegy'
url 'https://maven.gegy.dev'
content {
includeGroup 'dev.lambdaurora'
}
}
maven {
name 'TerraformersMC'
url 'https://maven.terraformersmc.com/'
content {
includeGroup 'com.terraformersmc'
}
}
}
configurations {
shadow
api.extendsFrom shadow
}
loom {
accessWidenerPath = file("src/main/resources/lambdabettergrass.accesswidener")
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${project.quilt_mappings}:intermediary-v2"
modImplementation "org.quiltmc:quilt-loader:${project.loader_version}"
modules.stream().map { "org.quiltmc.qsl.${it[0]}:${it[1]}:${project.qsl_version}+${project.minecraft_version}" }
.forEach {
modImplementation(it) {
exclude module: "quilt-loader"
}
}
// Fabric API.
fabricModules.stream().map { "org.quiltmc.quilted-fabric-api:${it}:${project.fabric_api_version}-${project.minecraft_version}" }
.forEach {
modImplementation(it) {
exclude module: "quilt-loader"
}
}
runtimeModules.stream().map { "org.quiltmc.quilted-fabric-api:${it}:${project.fabric_api_version}-${project.minecraft_version}" }
.forEach {
modImplementation(it) {
exclude module: "quilt-loader"
}
}
modLocalRuntime("org.quiltmc.qsl.entity:entity_events:${project.qsl_version}+${project.minecraft_version}") {
exclude module: "quilt-loader"
}
include modImplementation("dev.lambdaurora:spruceui:${project.spruceui_version}")
modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}") {
transitive = false
}
shadow 'com.electronwill.night-config:core:3.6.3'
shadow 'com.electronwill.night-config:toml:3.6.3'
}
java {
sourceCompatibility = JavaVersion.toVersion(targetJavaVersion)
targetCompatibility = JavaVersion.toVersion(targetJavaVersion)
withSourcesJar()
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
it.options.deprecation(true)
it.options.incremental(true)
it.options.release.set(targetJavaVersion)
}
processResources {
inputs.property 'version', project.version
filesMatching('fabric.mod.json') {
expand 'version': project.version
}
filesMatching('quilt.mod.json') {
expand 'version': project.version
}
}
jar {
from('LICENSE') {
rename { "${it}_${project.archivesBaseName}" }
}
}
license {
rule file('HEADER')
include '**/*.java'
}
shadowJar {
dependsOn jar
configurations = [project.configurations.shadow]
destinationDirectory.set(file("${project.buildDir}/devlibs"))
archiveClassifier.set('dev')
relocate 'com.electronwill.nightconfig', 'dev.lambdaurora.lambdabettergrass.shadow.nightconfig'
}
remapJar.dependsOn(shadowJar)
modrinth {
projectId = project.modrinth_id
versionName = "LambdaBetterGrass ${project.mod_version} (${getMCVersionString()})"
gameVersions = [project.minecraft_version]
versionType = isMCVersionNonRelease() ? "beta" : "release"
loaders = ["quilt"]
uploadFile = tasks.remapJar
dependencies = [
new ModDependency("qvIfYCYJ", "required")
]
syncBodyFrom = parseReadme()
// Changelog fetching
def changelogContent = fetchChangelog()
if (changelogContent) {
changelog = changelogContent
} else {
afterEvaluate {
tasks.modrinth.setEnabled(false)
}
}
// If we don't have a MODRINTH_TOKEN, don't run the modrinth publish tasks.
if (!System.getenv("MODRINTH_TOKEN")) {
project.logger.debug('MODRINTH_TOKEN is not set! Disabled modrinth and modrinthSyncBody tasks.')
tasks.modrinth.setEnabled(false)
tasks.modrinthSyncBody.setEnabled(false)
}
}
curseforge {
if (System.getenv("CURSEFORGE_TOKEN")) {
apiKey = System.getenv("CURSEFORGE_TOKEN")
} else { // If we don't have a CURSEFORGE_TOKEN, don't run the curseforge publish tasks.
project.logger.debug('CURSEFORGE_TOKEN is not set! Disabled curseforge task.')
tasks.curseforge.setEnabled(false)
}
project {
id = project.curseforge_id
releaseType = this.getVersionType()
addGameVersion project.minecraft_version
addGameVersion "Quilt"
addGameVersion "Java 17"
addGameVersion "Java 18"
// Changelog fetching
def changelogContent = fetchChangelog()
if (changelogContent) {
changelogType = "markdown"
changelog = "Changelog:\n\n${changelogContent}"
} else {
afterEvaluate {
uploadTask.setEnabled(false)
}
}
mainArtifact(remapJar) {
displayName = "LambdaBetterGrass ${project.mod_version} (${project.minecraft_version})"
relations {
requiredDependency "qsl"
optionalDependency "modmenu"
incompatible "optifabric"
incompatible "fabric-api"
}
}
afterEvaluate {
uploadTask.setGroup("publishing")
uploadTask.dependsOn("remapJar")
}
}
}
tasks.curseforge.setGroup("publishing")
// Configure the maven publication.
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'LambdaBetterGrass'
description = 'Adds actual better grass to the game.'
}
}
}
repositories {
mavenLocal()
maven {
name = 'BuildDirLocal'
url = "$buildDir/repo"
}
}
}