forked from paulevsGitch/BetterEnd
-
Notifications
You must be signed in to change notification settings - Fork 42
/
build.gradle
390 lines (346 loc) · 12.6 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.114'
}
}
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
repositories {
maven { url "https://maven.dblsaiko.net/" }
maven { url "https://maven.fabricmc.net/" }
maven { url 'https://maven.blamejared.com' }
maven { url "https://maven.shedaniel.me/" }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.terraformersmc.com/releases' }
maven { url = "https://maven.terraformersmc.com/" }
maven { url "https://ladysnake.jfrog.io/artifactory/mods" }
maven { url = "https://dvs1.progwml6.com/files/maven/" }
maven { url = "https://modmaven.dev" }
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
flatDir {
dirs 'libs'
}
}
loom {
accessWidenerPath = file("src/main/resources/betterend.accesswidener")
interfaceInjection {
// When enabled injected interfaces from dependecies will be applied.
enableDependencyInterfaceInjection = true
}
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=betterend"
runDir "build/datagen"
}
}
}
sourceSets {
main {
// Add the datagenned files into the jar.
resources {
srcDirs += [
'src/main/generated'
]
}
}
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
//Disabled, no 1.20.3/4 version available
// modApi "vazkii.patchouli:Patchouli:${project.patchouli_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 "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
//needed for trinkets, otherwise BetterEnd would require users to install trinkets
// modApi "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}"
// modCompileOnly "dev.emi:trinkets:${project.trinkets_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')
}
}
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
}
javadoc {
options.tags = ["reason"]
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
// 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"
}
artifacts {
archives sourcesJar
archives javadocJar
}
def env = System.getenv()
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task release(dependsOn: [remapJar, sourcesJar, javadocJar]) {
onlyIf {
env.GITHUB_TOKEN
}
doLast {
def github = GitHub.connectUsingOAuth(env.GITHUB_TOKEN as String)
def repository = github.getRepository("quiqueck/BetterEnd")
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("${archivesBaseName}-${version}")
releaseBuilder.body("A changelog can be found at https://github.com/quiqueck/BetterEnd/commits")
releaseBuilder.commitish("master")
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-sources.jar"), "application/java-archive");
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-javadoc.jar"), "application/java-archive");
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
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 gitLogCmd = "git log $lastTag..HEAD --oneline --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 "rei"
optional.project "trinkets"
optional.project "patchouli"
}
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 = '413596'
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 'patchouli'
optionalDependency 'trinkets'
}
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
}
}