forked from paulevsGitch/BetterNether
-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.gradle
337 lines (296 loc) · 10.5 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
plugins {
id 'fabric-loom' version "${loom_version}"
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id "com.matthewprenger.cursegradle" version "1.4.0"
}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
def local_bclib = findProject(':BCLib') != null
def local_wunderlib = findProject(':WunderLib') != null
loom {
accessWidenerPath = file("src/main/resources/betternether.accesswidener")
runs {
// This adds a new gradle task that runs the datagen API: "gradlew runDatagenClient"
datagenClient {
inherit client
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}"
vmArg "-Dfabric-api.datagen.strict-validation"
vmArg "-Dfabric-api.datagen.modid=betternether"
runDir "build/datagen"
}
}
}
sourceSets {
main {
// Add the datagenned files into the jar.
resources {
srcDirs += [
'src/main/generated'
]
}
}
}
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// https://mvnrepository.com/artifact/javax.annotation/jsr305
compileOnly group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
// compile against the API
modCompileOnly "mcp.mobius.waila:wthit-api:fabric-${project.wthit_version}"
// run against the full jar
modRuntimeOnly "mcp.mobius.waila:wthit:fabric-${project.wthit_version}"
println "Using local BCLib: ${local_bclib}"
if (local_bclib) {
implementation project(path: ":BCLib", configuration: 'dev')
} else {
modImplementation "com.github.quiqueck:BCLib:${project.bclib_version}"
}
// modCompileOnly "dev.emi:emi-fabric:${emi_version}:api"
// modLocalRuntime "dev.emi:emi-fabric:${emi_version}"
if (local_wunderlib) {
println "Using local WunderLib"
implementation project(path: ":WunderLib", configuration: 'dev')
}
}
repositories {
mavenCentral()
//mavenLocal()
maven { url 'https://jitpack.io' }
maven { url "https://maven.bai.lol" }
maven { url 'https://maven.terraformersmc.com' }
flatDir {
dirs 'libs'
}
}
def useApi(String dep) {
dependencies.modImplementation(dep) {
exclude group: 'net.fabricmc.fabric-api'
exclude group: 'net.fabricmc'
if (!dep.contains("me.shedaniel")) {
exclude group: 'me.shedaniel.cloth'
exclude group: 'me.shedaniel'
}
}
}
processResources {
println "Version: ${project.version}"
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
it.options.release = 17
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = "sources"
from sourceSets.main.allSource
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from "LICENSE"
from "LICENSE.ASSETS"
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
//from https://lowcarbrob.medium.com/android-pro-tip-generating-your-apps-changelog-from-git-inside-build-gradle-19a07533eec4
String generateChangelog() {
println "Assembeling Changelog ..."
def lastTag = "git describe --tags --abbrev=0".execute().text.trim()
def gitLogCmd = "git log $lastTag..HEAD --oneline --no-merges --pretty=format:\"%s\"".execute().text.trim()
def features = ""
def fixes = ""
def changes = ""
gitLogCmd.eachLine { gitLine ->
def line = gitLine.substring(1, gitLine.length() - 1)
if (line.trim().startsWith("[")) {
def sline = line.split("]", 2)
if (sline.length == 2) {
def type = sline[0].trim().toLowerCase().substring(1)
def comment = sline[1].trim()
//filter issue links
if (comment.contains("(")) {
def cline = comment.split("\\(", 2)
if (cline.length == 2 && cline[1].contains("#")) {
comment = cline[0].trim()
}
}
if (type == "fix" || type == "fixes" || type == "fixed") {
fixes += "- $comment \n"
} else if (type == "feature" || type == "features") {
features += "- $comment \n"
} else if (type == "change" || type == "changes" || type == "changed") {
changes += "- $comment \n"
} else {
println "Unknown Type: $type ($line)"
}
}
}
}
def changelog = ""
if (!features.isEmpty()) {
changelog += "#### Features\n"
changelog += features.trim()
changelog += "\n\n"
}
if (!changes.isEmpty()) {
changelog += "#### Changes\n"
changelog += changes.trim()
changelog += "\n\n"
}
if (!fixes.isEmpty()) {
changelog += "#### Fixes\n"
changelog += fixes.trim()
changelog += "\n\n"
}
println "Changelog since $lastTag:\n$changelog"
return changelog
}
task changelog() {
doLast {
new File(projectDir, "CHANGES.md").text = generateChangelog()
}
}
modrinth {
def changes = new File(projectDir, "CHANGES.md")
if (changes.exists()) {
changes = changes.getText('UTF-8')
} else {
changes = ""
}
def modrinth_token = new File(projectDir, "../MODRINTH_TOKEN")
if (modrinth_token.exists()) {
modrinth_token = modrinth_token.text
} else {
modrinth_token = ""
}
def slurper = new groovy.json.JsonSlurper()
token = modrinth_token
projectId = project.modrinth_id
versionNumber = project.mod_version
versionType = project.release_channel
uploadFile = remapJar
gameVersions = slurper.parseText(project.modrinth_versions)
loaders = ["fabric"]
changelog = changes
dependencies {
required.project "fabric-api"
required.project "bclib"
optional.project "emi"
optional.project "wthit"
}
debugMode = false
}
curseforge {
def slurper = new groovy.json.JsonSlurper()
apiKey = new File(projectDir, "../CURSEFORGE_TOKEN")
if (apiKey.exists()) {
apiKey = apiKey.text
} else {
apiKey = ""
}
def changes = new File(projectDir, "CHANGES.md")
if (changes.exists()) {
changes = changes.getText('UTF-8')
} else {
changes = ""
}
project {
id = '311377'
changelogType = 'markdown'
changelog = changes
releaseType = project.release_channel
def versions = slurper.parseText(project.modrinth_versions);
def latestVersion = ''
for (v in versions) {
addGameVersion v
latestVersion = "[$v]"
}
addGameVersion 'Fabric'
addGameVersion 'Java 17'
relations {
requiredDependency 'fabric-api'
requiredDependency 'bclib'
optionalDependency 'emi'
optionalDependency 'roughly-enough-items'
optionalDependency 'wthit'
}
mainArtifact(remapJar) {
displayName = "$project.modrinth_id-$project.version $latestVersion"
}
afterEvaluate {
mainArtifact(remapJar.outputs)
}
}
options {
debug = false
forgeGradleIntegration = false
}
}
task nextVersion() {
doLast {
def inputFile = new File('modrinth.json')
def gameVersions = java.net.URLEncoder.encode(project.modrinth_versions, "UTF-8")
new URL("https://api.modrinth.com/v2/project/${project.modrinth_id}/version?&game_versions=${gameVersions}").withInputStream { i -> inputFile.withOutputStream { it << i } }
def json = new groovy.json.JsonSlurper().parseText(inputFile.text)
def version = json[0].version_number
//increment patch version
def indexedVersionList = version.split(/\./).toList().withIndex()
indexedVersionList = indexedVersionList.collect { num, idx -> num.toInteger() }
indexedVersionList[2] = indexedVersionList[2].value + 1
def updatedVersion = indexedVersionList.join(".")
println "\n\n"
println "------------- CURRENT VERSION -------------"
println "Last Published Version: " + version
println " Game Versions: " + json[0].game_versions
println " Status: " + json[0].status
println " Featured: " + json[0].featured
println " Downloaded: " + json[0].downloads
println "\n"
println "-------------- NEXT VERSION ---------------"
println "Next Version: " + updatedVersion
println "\n\n"
def propertiesFile = new File("gradle.properties")
def newContents = propertiesFile.text.replaceFirst("mod_version=\\d+.\\d+.\\d+", "mod_version=${updatedVersion}")
propertiesFile.text = newContents
}
}