-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
222 lines (194 loc) · 8.06 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
plugins {
id 'java'
id 'net.darkhax.curseforgegradle' version '1.1.+'
}
group 'team.creative'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
import groovy.json.*
gradle.afterProject { project ->
if (project != rootProject) {
project.tasks.getByName("processResources") {
outputs.upToDateWhen { false }
filesMatching('pack.mcmeta') {
def input = openJsonFile(getFile())
processJson([description: project.mod_name + " resources", pack_format: resource_pack_format,
"forge:resource_pack_format": resource_pack_format, "forge:data_pack_format": data_pack_format], input)
saveJsonFile(input, getFile())
}
filesMatching('fabric.mod.json') {
def input = openJsonFile(getFile())
processJson([id: project.mod_id, version: project.mod_version, name: project.mod_name, description: project.mod_description,
license: project.mod_license, icon: project.mod_id + ".png", fabricloader: loader_version_range, "fabric-api": "*", minecraft: minecraft_version_range], input)
if (project.hasProperty("modDependencies")) {
project.modDependencies.each {
dependency -> {
input["depends"][dependency.key] = dependency.value
}
}
}
saveJsonFile(input, getFile())
}
}
project.java.withSourcesJar()
def modFilePrefix = "FABRIC"
if (project.hasProperty("mod_release_suffix") && project.mod_release_suffix != "") {
modFilePrefix = project.mod_release_suffix
}
project.remapJar {
archiveFileName.set(project.mod_name + "_" + modFilePrefix + "_v" + project.mod_version + "_mc" + project.minecraft_version + ".jar")
}
project.sourcesJar {
exclude('assets/*')
exclude('data/*')
archiveFileName.set(project.mod_name + "_" + modFilePrefix + "_SOURCE_v" + project.mod_version + "_mc" + project.minecraft_version + ".jar")
}
project.remapSourcesJar {
archiveFileName.set(project.mod_name + "_" + modFilePrefix + "_SOURCE_v" + project.mod_version + "_mc" + project.minecraft_version + ".jar")
}
project.jar {
from("LICENSE") {
rename { "${it}" }
}
}
project.loom.runConfigs.configureEach {
ideConfigGenerated = true
vmArgs "-Dfabric.debug.replaceVersion=${project.mod_id}:${project.mod_version}"
}
project.java.toolchain.languageVersion = JavaLanguageVersion.of(21)
def targetJavaVersion = 21
project.tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
options.compilerArgs += ["-Xmaxerrs", "1000"];
}
project.java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
project.tasks.register('upload', GradleBuild) {
description 'Uploads new version to modrinth and curseforge.'
group = 'publishing'
tasks = ['curseforge', 'modrinth']
}
project.gradle.taskGraph.whenReady {
if (it.hasTask(project.tasks.modrinth) || it.hasTask(project.tasks.curseforge)) {
if (!getChangelogText(project)?.trim()) {
throw new GradleException('No changelog provided')
}
}
}
project.tasks.modrinth.enabled = System.getenv("MODRINTH_TOKEN") != null
project.tasks.modrinth.group = 'publishing'
project.modrinth {
token = System.getenv("MODRINTH_TOKEN")
if (project.hasProperty("modrinth_id")) {
projectId = project.modrinth_id
} else {
projectId = project.mod_id
}
versionNumber = project.mod_version
versionType = project.release_type
uploadFile = project.remapJar
gameVersions = [ project.minecraft_version ]
changelog = getChangelogText(project)
dependencies {
required.project "fabric-api"
if (project.hasProperty("modDependencies")) {
project.modDependencies.each {
dependency -> {
required.project dependency.key
}
}
}
}
additionalFiles = [ project.sourcesJar ]
}
project.tasks.register("curseforge", net.darkhax.curseforgegradle.TaskPublishCurseForge) {
group = 'publishing'
apiToken = System.getenv("CURSEFORGE_TOKEN") != null ? System.getenv("CURSEFORGE_TOKEN") : "empty"
disableVersionDetection()
def mainFile = upload(project.curse_id, project.remapJar)
mainFile.releaseType = project.release_type
mainFile.changelog = getChangelogText(project)
mainFile.changelogType = 'markdown'
mainFile.addModLoader("Fabric")
mainFile.addGameVersion(project.minecraft_version)
if (project.hasProperty("modSides") && project.modSides instanceof List && !project.modSides.isEmpty()) {
project.modSides.each {
side -> {
mainFile.addEnvironment(side)
}
}
} else {
mainFile.addEnvironment("client", "server")
}
if (project.hasProperty("modDependencies") && project.modDependencies instanceof List && !project.modDependencies.isEmpty()) {
project.modDependencies.each {
key, dependency -> {
mainFile.addRequirement(key)
}
}
}
def sourcesFile = mainFile.withAdditionalFile(project.sourcesJar)
sourcesFile.changelog = getChangelogText(project)
sourcesFile.changelogType = 'markdown'
}
}
}
String getChangelogText(project) {
String result = ''
boolean first = true
project.file('changelog.txt').readLines().find {
if (first) {
if (it.equals(project.mod_version)) {
first = false
}
return false
} else if (!it?.trim()) {
return true
} else {
result += "* " + it + "\n"
return false
}
}
return result
}
Object openJsonFile(file) {
String fileContents = file.text.replaceAll(/\$\{[^}]*\}/, "0")
def input = new JsonSlurper().parseText(fileContents)
return input
}
void saveJsonFile(input, file) {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(JsonOutput.prettyPrint(JsonOutput.toJson(input)).replace("\n", "\r\n"));
writer.close();
}
void processJson(properties, object) {
object.each {
entry -> {
if(entry.value instanceof Map) {
processJson(properties, entry.value)
} else if(properties.keySet().contains(entry.key)) {
entry.value = properties.get(entry.key)
if(entry.value.isNumber()) {
entry.value = entry.value.toInteger()
}
}
}
}
}