-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
434 lines (382 loc) · 14.7 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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
plugins {
id 'net.neoforged.gradle.userdev' version '7.0.145'
id 'net.darkhax.curseforgegradle' version '1.0.8'
id 'com.github.kt3k.coveralls' version '2.12.0'
id 'com.diffplug.spotless' version '6.25.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.modrinth.minotaur' version '2.+'
}
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
import net.neoforged.gradle.common.tasks.PotentiallySignJar
import net.darkhax.curseforgegradle.Constants
import net.darkhax.curseforgegradle.TaskPublishCurseForge
// Determine build number
String build_number = "DEV" // this will be referenced as simply build_number from now on.
if (System.getenv().BUILD_NUMBER)
build_number = System.getenv().BUILD_NUMBER
if (System.getenv().GITHUB_RUN_ID)
build_number = System.getenv().GITHUB_RUN_NUMBER
if (System.getenv().RELEASE)
build_number = "RELEASE"
logger.lifecycle "BUILDING VERSION: " + build_number
// Include build number in version
if (build_number.equals("RELEASE"))
version = "${project.mod_version}"
else
version = "${project.mod_version}-${build_number}"
base {
archivesName = "${mod_id}-${minecraft_version}-neoforge"
}
java {
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
}
compileJava.options.compilerArgs << "-Xmaxerrs" << "9999"
// Load secrets
def getSecrets() {
Properties props = new Properties()
if (file('./secrets.properties').exists()) {
props.load(new FileInputStream(file('./secrets.properties')))
}
return props
}
def getCurseforgeKey() {
if(secrets.curseforge_key) {
return secrets.curseforge_key
} else if(System.getenv().GITHUB_ACTIONS && System.getenv().CURSEFORGE_KEY_SECRET) {
return System.getenv().CURSEFORGE_KEY_SECRET
} else {
return "DUMMY"
}
}
def getModrinthKey() {
if(secrets.modrinth_key) {
return secrets.modrinth_key
} else if(System.getenv().GITHUB_ACTIONS && System.getenv().MODRINTH_KEY_SECRET) {
return System.getenv().MODRINTH_KEY_SECRET
} else {
return "DUMMY"
}
}
def getChangelog() {
if (System.getenv().RELEASE) {
return file("./resources/changelog/${project.minecraft_version}-${project.mod_version}.txt").getText();
} else {
return "Changes since last release: ${project.github_url}/compare/${project.minecraft_version}-${project.mod_version}...${System.getenv().GITHUB_SHA}"
}
}
//ext {
Properties secrets = getSecrets();
secrets.curseforgeKey = getCurseforgeKey();
secrets.modrinthKey = getModrinthKey();
secrets.changelog = getChangelog();
secrets.build_number = build_number;
//}
sourceSets {
main
test
}
sourceSets.main.resources { srcDir 'src/generated/resources' }
configurations {
modLib
implementation.extendsFrom modLib
}
test {
testLogging {
exceptionFormat = 'full'
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
name "Cyclops Repo"
url "https://maven.pkg.github.com/CyclopsMC/packages"
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME") ?: System.getenv("GITHUB_USER")
password = project.findProperty("gpr.key") ?: System.getenv("MAVEN_KEY") ?: System.getenv("GITHUB_TOKEN")
}
}
}
dependencies {
implementation "net.neoforged:neoforge:${project.neoforge_version}"
// Add something like 'cyclopscore_version_local=0.1.0-DEV' to your secrets.properties if you want to use a custom local CyclopsCore version.
if(secrets.cyclopscore_version_local) {
implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${secrets.cyclopscore_version_local}:deobf"
} else {
implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${project.cyclopscore_version}:deobf"
}
// Add something like 'integrateddynamics_version_local=0.1.0-DEV' to your secrets.properties if you want to use a custom local Integrated Tunnels Compat version.
if(secrets.integrateddynamics_version_local) {
implementation "org.cyclops.integrateddynamics:integrateddynamics-${project.minecraft_version}-neoforge:${secrets.integrateddynamics_version_local}:deobf"
} else {
implementation "org.cyclops.integrateddynamics:integrateddynamics-${project.minecraft_version}-neoforge:${project.integrateddynamics_version}:deobf"
}
if(secrets.commoncapabilities_version_local) {
implementation "org.cyclops.commoncapabilities:commoncapabilities-${project.minecraft_version}-neoforge:${secrets.commoncapabilities_version_local}:deobf"
} else {
implementation("org.cyclops.commoncapabilities:commoncapabilities-${project.minecraft_version}-neoforge:${project.commoncapabilities_version}") { // https://dl.bintray.com/cyclopsmc/dev/org/cyclops/commoncapabilities/CommonCapabilities/
transitive = false
}
}
modLib "com.google.re2j:re2j:1.1"
modLib ("io.netty:netty-codec-http:4.1.77.Final") {
transitive = false
}
modLib "org.graalvm.sdk:graal-sdk:22.3.2"
shadow "org.graalvm.sdk:graal-sdk:22.3.2"
modLib ("org.graalvm.js:js:22.3.2") {
exclude group: 'com.ibm.icu', module: 'icu4j'
}
shadow "org.graalvm.js:js:22.3.2"
// Project lombok
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
testCompileOnly 'org.projectlombok:lombok:1.18.30'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
testImplementation "junit:junit:4.12"
testImplementation "org.mockito:mockito-core:1.+"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.8.2"
}
subsystems {
parchment {
minecraftVersion = "${project.parchment_minecraft_version}"
mappingsVersion = "${project.parchment_version}"
}
}
runs {
configureEach {
systemProperty 'forge.logging.markers', 'REGISTRIES'
systemProperty 'forge.logging.console.level', 'debug'
systemProperty 'forge.logging.console.level', 'debug'
modSource project.sourceSets.main
dependencies {
runtime project.configurations.modLib
}
}
client {
systemProperty 'neoforge.enabledGameTestNamespaces', "cyclopscore,${mod_id}"
}
server {
systemProperty 'neoforge.enabledGameTestNamespaces', "cyclopscore,${mod_id}"
programArgument '--nogui'
}
gameTestServer {
systemProperty 'neoforge.enabledGameTestNamespaces', "cyclopscore,${mod_id}"
}
data {
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
}
jar {
archiveClassifier.set('slim')
manifest {
attributes([
"Specification-Title": "${project.name}",
"Specification-Vendor": "rubensworks",
"Specification-Version": "${project.mod_version}",
"Implementation-Title": "${project.name}",
"Implementation-Version": "${project.mod_version}",
"Implementation-Vendor" :"rubensworks",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
task signJar(type: PotentiallySignJar, dependsOn: jar) {
dependsOn(tasks.jar)
onlyIf {
System.getenv().SIGN_KEYSTORE
}
keyStore = System.getenv().SIGN_KEYSTORE
alias = System.getenv().SIGN_ALIAS
storePass = System.getenv().SIGN_STOREPASS
keyPass = System.getenv().SIGN_KEYPASS
input = jar.archivePath
output = jar.archivePath
}
task deobfJar(type: Jar) {
from sourceSets.main.output
archiveClassifier.set('deobf')
manifest {
attributes([
"Specification-Title": "${project.name}",
"Specification-Vendor": "rubensworks",
"Specification-Version": "${project.mod_version}",
"Implementation-Title": "${project.name}",
"Implementation-Version": "${project.mod_version}",
"Implementation-Vendor" :"rubensworks",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
task sourcesJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set('sources')
from sourceSets.main.allJava
}
task javadocJar(type: Jar, dependsOn: javadoc) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
shadowJar {
mergeServiceFiles() // To fix graal issue: https://github.com/oracle/graaljs/issues/125
configurations = [project.configurations.shadow]
archiveClassifier.set(''); // Replace the default JAR
// To avoid clashes with other mods
relocate 'org.graalvm', 'org.cyclops.integratedscripting.vendors.org.graalvm'
relocate 'com.oracle', 'org.cyclops.integratedscripting.vendors.com.oracle'
relocate 'com.ibm', 'org.cyclops.integratedscripting.vendors.com.ibm'
}
assemble.dependsOn shadowJar
jar {
shadowJar {}
}
artifacts {
archives shadowJar
archives deobfJar
archives sourcesJar
archives javadocJar
}
// Replace properties in files
processResources {
def expandProps = [
'mod_version' : mod_version,
'group' : project.group, //Else we target the task's group.
'minecraft_version' : minecraft_version,
'mod_name' : mod_name,
'mod_author' : mod_author,
'mod_id' : mod_id,
'license' : license,
'issue_tracker_url' : issue_tracker_url,
'display_url' : display_url,
'description' : project.description,
'neoforge_version' : neoforge_version,
'neoforge_loader_version_range' : neoforge_loader_version_range,
'neoforge_update_json_url' : neoforge_update_json_url,
'java_version' : java_version,
'cyclopscore_version' : cyclopscore_version,
'cyclopscore_version_semver' : cyclopscore_version.replaceAll("-.*\$", ""),
'commoncapabilities_version' : commoncapabilities_version,
'commoncapabilities_version_semver' : commoncapabilities_version.replaceAll("-.*\$", ""),
'integrateddynamics_version' : integrateddynamics_version,
'integrateddynamics_version_semver' : integrateddynamics_version.replaceAll("-.*\$", "")
]
filesMatching(['pack.mcmeta', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', 'mixins.*.json']) {
expand expandProps
}
inputs.properties(expandProps)
}
task publishCurseForge(type: TaskPublishCurseForge) {
dependsOn(tasks.jar)
apiToken = secrets.curseforgeKey;
def mainFile = upload(project.curseforge_project_id, shadowJar)
mainFile.releaseType = secrets.build_number.equals("RELEASE") ? Constants.RELEASE_TYPE_RELEASE : Constants.RELEASE_TYPE_BETA
mainFile.changelogType = "text"
mainFile.changelog = secrets.changelog
mainFile.addJavaVersion("Java ${project.java_version}")
mainFile.addGameVersion(project.minecraft_version)
mainFile.addModLoader("NeoForge")
mainFile.addRequirement("cyclops-core")
mainFile.addRequirement('integrated-dynamics')
}
modrinth {
token = secrets.modrinthKey;
projectId = "${modrinth_project_id}"
versionNumber = project.minecraft_version + '-' + project.version
versionName = "${project.version} for NeoForge ${project.minecraft_version}"
versionType = secrets.build_number.equals("RELEASE") ? "release" : "beta"
uploadFile = shadowJar
gameVersions = [ project.minecraft_version ]
changelog = provider { secrets.changelog }
dependencies {
required.project "Z9DM0LJ4" // Cyclops Core
required.project "yYzdQHJI" // Integrated Dynamics
}
}
publishing {
repositories {
if (project.hasProperty("filesmaven_url")) {
logger.info('Publishing to files server')
maven {
url project.filesmaven_url
credentials {
username = project.filesmaven_username
password = project.filesmaven_key
}
}
} else if (System.getenv("MAVEN_URL")) {
logger.info('Publishing to files server')
maven {
url System.getenv("MAVEN_URL")
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_KEY")
}
}
} else {
logger.error('No maven repo was set!')
}
}
publications { PublicationContainer publicationContainer ->
publicationContainer.register("maven", MavenPublication) { MavenPublication publication ->
publication.artifacts = [shadowJar, javadocJar, deobfJar, sourcesJar]
publication.artifactId = project.archivesBaseName.toLowerCase() // GH can't handle uppercase...
}
}
}
idea {
module {
downloadSources = true
downloadJavadoc = true
for (String excludeDirName in ["run", "out", "logs", "gradle"]) {
File excludeDir = new File(projectDir, excludeDirName)
excludeDirs.add(excludeDir)
}
}
}
jacocoTestReport {
// Include unit and game test coverage
executionData fileTree(project.buildDir).include("jacoco/*.exec")
reports {
xml.required = true
html.required = true
}
}
// Also measure coverage for game tests
tasks.whenTaskAdded { task ->
if (task.name.equals('runGameTestServer')) {
jacocoTestReport.dependsOn test, task
jacoco {
toolVersion = "0.8.12"
applyTo task
}
}
}
spotless {
java {
target 'src/*/java/org/cyclops/**/*.java'
endWithNewline()
trimTrailingWhitespace()
removeUnusedImports()
indentWithSpaces()
}
}
tasks.register('updateGitHooks', Copy) {
from './scripts/pre-commit'
into './.git/hooks'
}
compileJava.dependsOn updateGitHooks
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
// The following is required to fix running unit tests during build phase
tasks.configureEach { task ->
if (task.name.startsWith("test")) {
task.enabled = true
}
if (task.name.startsWith("testJunit")) {
task.enabled = false
}
}