forked from TechReborn/TechReborn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
401 lines (342 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
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
391
392
393
394
395
396
397
398
399
400
401
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.135'
}
}
plugins {
id 'java'
id 'groovy'
id 'java-library'
id 'idea'
id 'eclipse'
id 'maven-publish'
id "org.cadixdev.licenser" version "0.6.1"
id "fabric-loom" version "0.11-SNAPSHOT"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "de.undercouch.download" version "4.1.1"
}
repositories {
maven {
url = "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven {
name "DashLoader"
url = "https://maven.oskarstrom.net"
content {
includeGroup "net.oskarstrom"
}
}
maven {
name "REI"
url "https://maven.shedaniel.me/"
content {
includeGroup "me.shedaniel"
includeGroup "me.shedaniel.cloth"
includeGroup "dev.architectury"
}
}
maven {
url = 'https://ladysnake.jfrog.io/artifactory/mods'
content {
// Trinkets dependency
includeGroup "io.github.onyxstudios.Cardinal-Components-API"
}
}
maven {
url = "https://jitpack.io"
content {
// Trinkets API
includeGroup "com.github.emilyploszaj"
}
}
}
def ENV = System.getenv()
license {
header file('HEADER')
include '**/*.java'
include '**/*.groovy'
ignoreFailures = true //Stops the build from failing if a file does not have a license header
}
group = 'TechReborn'
allprojects {
version = project.mod_version + (ENV.GITHUB_ACTIONS ? "" : "+local")
apply plugin: "fabric-loom"
apply plugin: "maven-publish"
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
loom {
runtimeOnlyLog4j = true
}
// Shared deps between TR and RC
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_version}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
//Fabric api
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fapi_version}"
include(modApi("teamreborn:energy:${project.energy_version}")) {
transitive = false
}
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 17
}
java {
withSourcesJar()
}
publishing {
publications {
maven(MavenPublication) {
groupId project.name
artifactId project.archivesBaseName + "-" + getBranch()
version project.version
from components.java
}
}
repositories {
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
}
}
processResources {
doLast {
// Depend on the reborn core version it was built against
fileTree(dir: outputs.files.asPath, include: "fabric.mod.json").each {
def jsonSlurper = new JsonSlurper()
def modJson = jsonSlurper.parseText(it.text)
modJson.depends.reborncore = "~${project.version}"
it.text = JsonOutput.toJson(modJson)
}
}
}
loom {
accessWidenerPath = file("src/main/resources/techreborn.accesswidener")
}
sourceSets {
// Add a data gen sourceset
datagen {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
}
gametest {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
}
main {
resources {
srcDirs += [
'src/main/generated'
]
}
}
}
// TechReborn specific dependencies
dependencies {
api project(path: ":RebornCore", configuration: "namedElements")
include project(":RebornCore")
optionalDependency "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
disabledOptionalDependency "com.github.emilyploszaj:trinkets:${project.trinkets_version}"
disabledOptionalDependency "net.oskarstrom:DashLoader:${project.dashloader_version}"
// Use groovy for datagen/gametest, if you are copying this you prob dont want it.
gametestImplementation 'org.apache.groovy:groovy:4.0.0'
datagenImplementation 'org.apache.groovy:groovy:4.0.0'
gametestImplementation ("com.google.truth:truth:1.1.3") {
exclude module: "guava"
exclude module: "asm"
}
}
def optionalDependency(String dep) {
dependencies.modLocalRuntime (dep) {
exclude group: "net.fabricmc.fabric-api"
exclude module: "nbt-crafting"
}
dependencies.modCompileOnly (dep) {
exclude group: "net.fabricmc.fabric-api"
exclude module: "nbt-crafting"
}
}
def disabledOptionalDependency(String dep) {
dependencies.modCompileOnly (dep) {
exclude group: "net.fabricmc.fabric-api"
exclude module: "nbt-crafting"
}
}
loom {
runs {
// Add a data gen run config
datagen {
server()
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}"
vmArg "-Dfabric-api.datagen.modid=techreborn-datagen"
runDir "build/datagen"
source sourceSets.datagen
}
// Use to run the tests
gametest {
server()
name "Game Test"
vmArg "-Dfabric-api.gametest"
vmArg "-Dfabric-api.gametest.report-file=${project.buildDir}/junit.xml"
runDir "build/gametest"
source sourceSets.gametest
}
// Use to debug tests
gametestClient {
client()
name "Game Test Client"
source sourceSets.gametest
}
}
}
test.dependsOn runGametest
runDatagen {
// Doesn't re-run the task when its up-to date
outputs.dir('src/main/generated')
}
jar {
exclude "**/*.psd"
from file('src/main/generated')
from { crowdin.getDidWork() ? fileTree('build/translations').matching{exclude "**/en_US.json"} : null}
// A bit of a hack to allow the generated sources when they already exist
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn 'fixTranslations'
dependsOn 'runDatagen'
}
task crowdinExport() {
description "Triggers crowdin to export the latest translations"
onlyIf {
ENV.CROWDIN_KEY
}
doLast{
def apiKey = ENV.CROWDIN_KEY
def projectId = 'techreborn'
def response = new URL(sprintf('https://api.crowdin.com/api/project/%1$s/export?key=%2$s', [projectId, apiKey])).text
def metadata = new XmlParser().parseText(response)
project.logger.lifecycle("crowdin export status: " + metadata.@status)
}
}
task crowdin(type: Download, dependsOn: 'crowdinExport'){
description "Downloads translations from CrowdIn"
src 'https://crowdin.com/backend/download/project/techreborn.zip'
dest file("build/translations.zip")
overwrite true
}
task cleanCrowdin(type: Delete){
description "Delete old translations"
delete 'build/translations'
}
task renameCrowdin(type: Copy, dependsOn: ['crowdin', 'cleanCrowdin']){
description "Renames the translation files to be all lower case"
mustRunAfter 'crowdin'
from zipTree(file("build/translations.zip"))
into file('build/translations')
rename {
String filename -> return filename.toLowerCase()
}
doFirst {
file('build/translations').deleteDir()
}
}
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
task fixTranslations(dependsOn: ['renameCrowdin']) {
description "Remove all translations that do not have an entry, ensures that minecraft falls back to EN_US over writing out an empty string"
def jsonSlurper = new JsonSlurper()
doLast {
file('build/translations').eachFileRecurse(groovy.io.FileType.FILES) {
if(it.name.endsWith(".json")) {
def lang = jsonSlurper.parseText(it.text)
lang.values().removeIf { val -> val.empty}
it.text = JsonOutput.prettyPrint(JsonOutput.toJson(lang))
}
}
}
}
import groovy.util.XmlSlurper
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
}
project {
id = "233564"
changelog = ENV.CHANGELOG ?: "No changelog provided"
releaseType = ENV.RELEASE_CHANNEL ?: "release"
addGameVersion "1.18.2" // Also update in RebornCore/build.gradle
addGameVersion "Fabric"
mainArtifact remapJar
relations {
requiredDependency 'reborncore'
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
forgeGradleIntegration = false
}
}
def getBranch() {
def ENV = System.getenv()
if (ENV.GITHUB_REF) {
def branch = ENV.GITHUB_REF
return branch.substring(branch.lastIndexOf("/") + 1)
}
return "unknown"
}
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: remapJar) {
onlyIf {
ENV.GITHUB_TOKEN
}
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("${archivesBaseName}-${version}")
releaseBuilder.body(ENV.CHANGELOG)
releaseBuilder.commitish(getBranch())
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive")
ghRelease.uploadAsset(file("RebornCore/build/libs/RebornCore-${version}.jar"), "application/java-archive")
}
}
github.dependsOn(project(":RebornCore").getTasks().getByName("remapJar"))
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.modmuss50.me/TechReborn/TechReborn-1.17/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
if (versions.contains(version)) {
throw new RuntimeException("${version} has already been released!")
}
}
}
github.mustRunAfter checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion