-
Notifications
You must be signed in to change notification settings - Fork 69
/
build.gradle.kts
465 lines (406 loc) · 15 KB
/
build.gradle.kts
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace
import java.nio.charset.StandardCharsets
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.util.*
plugins {
java
`maven-publish`
signing
idea
id("net.minecraftforge.gradle").version("6.0.18")
id("wtf.gofancy.fancygradle").version("1.1.3-0")
id("org.spongepowered.mixin").version("0.7-SNAPSHOT")
id("com.github.johnrengelman.shadow").version("7.1.2")
id("com.github.hierynomus.license").version("0.16.1")
id("io.github.opencubicchunks.gradle.mcGitVersion")
id("io.github.opencubicchunks.gradle.mixingen")
}
val licenseYear: String by project
val projectName: String by project
val doRelease: String by project
val theForgeVersion: String by project
logger.error(project.gradle.gradleVersion)
group = "io.github.opencubicchunks"
base {
archivesName.set("CubicChunks")
}
mcGitVersion {
isSnapshot = true
setCommitVersion("tags/v0.0", "0.0")
}
java.toolchain.languageVersion.set(JavaLanguageVersion.of(8))
fancyGradle {
patches {
resources
coremods
codeChickenLib
asm
mergetool
}
}
minecraft {
mappings("stable", "39-1.12")
val args = listOf(
"-Dfml.coreMods.load=io.github.opencubicchunks.cubicchunks.core.asm.coremod.CubicChunksCoreMod", //the core mod class, needed for mixins
"-Dmixin.env.compatLevel=JAVA_8", //needed to use java 8 when using mixins
"-Dmixin.debug.verbose=true", //verbose mixin output for easier debugging of mixins
"-Dmixin.debug.export=true", //export classes from mixin to runDirectory/.mixin.out
"-Dcubicchunks.debug=true", //various debug options of cubic chunks mod. Adds items that are not normally there!
"-XX:-OmitStackTraceInFastThrow", //without this sometimes you end up with exception with empty stacktrace
"-Dmixin.checks.interfaces=true", //check if all interface methods are overriden in mixin
"-Dfml.noGrab=false", //change to disable Minecraft taking control over mouse
"-ea", //enable assertions
"-da:io.netty..." //disable netty assertions because they sometimes fail
)
runs {
create("client") {
workingDirectory(project.file("run"))
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
property("forge.logging.console.level", "debug")
jvmArgs(args)
}
create("server") {
workingDirectory(project.file("run"))
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
property("forge.logging.console.level", "debug")
jvmArgs(args)
}
}
}
sourceSets {
create("optifine_dummy")
// TODO: make this unnecessary, it's an awful hack
create("api") {
if (!System.getProperty("idea.sync.active", "false").toBoolean()) {
java {
srcDir("CubicChunksAPI/src/main/java")
}
resources {
srcDir("CubicChunksAPI/src/main/resources")
}
compileClasspath = sourceSets.main.get().compileClasspath
}
}
}
val embed: Configuration by configurations.creating
val coreShadow: Configuration by configurations.creating
configurations {
implementation {
extendsFrom(embed)
extendsFrom(coreShadow)
}
}
repositories {
mavenCentral()
maven {
setUrl("https://files.minecraftforge.net/maven/")
}
maven {
setUrl("https://oss.sonatype.org/content/repositories/public/")
}
maven {
setUrl("https://repo.spongepowered.org/maven")
}
}
dependencies {
minecraft(group = "net.minecraftforge", name = "forge", version = theForgeVersion)
embed("com.flowpowered:flow-noise:1.0.1-SNAPSHOT")
compileOnly(sourceSets["optifine_dummy"].output)
testImplementation("junit:junit:4.13.2")
testImplementation("org.hamcrest:hamcrest-junit:2.0.0.0")
testImplementation("it.ozimov:java7-hamcrest-matchers:1.3.0")
testImplementation("org.mockito:mockito-core:4.2.0")
testImplementation("org.spongepowered:launchwrappertestsuite:1.0-SNAPSHOT")
coreShadow("org.spongepowered:mixin:0.8.1-SNAPSHOT") {
isTransitive = false
}
embed("io.github.opencubicchunks:regionlib:0.78.0-SNAPSHOT")
implementation("io.github.opencubicchunks:cubicchunks-api:1.12.2-0.0-SNAPSHOT")
if (!System.getProperty("idea.sync.active", "false").toBoolean()) {
annotationProcessor("org.spongepowered:mixin:0.8.4:processor")
}
}
idea {
module.apply {
inheritOutputDirs = true
}
module.isDownloadJavadoc = true
module.isDownloadSources = true
}
mixin {
val forgeMinorVersion = theForgeVersion.split(Regex("-")).getOrNull(1)?.split(Regex("\\."))?.getOrNull(1)
?: throw IllegalStateException("Couldn't parse forge version")
token("MC_FORGE", forgeMinorVersion)
}
sourceSets.main {
ext["refMap"] = "cubicchunks.mixins.refmap.json"
}
mixinGen {
filePattern = "cubicchunks.mixins.%s.json"
defaultRefmap = "cubicchunks.mixins.refmap.json"
defaultPackagePrefix = "io.github.opencubicchunks.cubicchunks.core.asm.mixin"
defaultCompatibilityLevel = "JAVA_8"
defaultMinVersion = "0.7.10"
config("core") {
required = true
conformVisibility = true
injectorsDefaultRequire = 1
}
config("fixes") {
required = false
conformVisibility = true
}
config("noncritical") {
required = false
conformVisibility = true
}
config("selectable") {
required = true
conformVisibility = true
injectorsDefaultRequire = 1
configurationPlugin = "io.github.opencubicchunks.cubicchunks.core.asm.CubicChunksMixinConfig"
}
}
tasks {
test {
systemProperty("lwts.tweaker", "cubicchunks.tweaker.MixinTweakerServer")
jvmArgs("-Dmixin.debug.verbose=true", //verbose mixin output for easier debugging of mixins
"-Dmixin.checks.interfaces=true", //check if all interface methods are overriden in mixin
"-Dmixin.env.remapRefMap=true")
testLogging {
showStandardStreams = true
}
}
fun substituteVersion(jar: Jar) {
val fs = FileSystems.newFileSystem(jar.archiveFile.get().asFile.toPath(), jar.javaClass.classLoader)
var str = String(Files.readAllBytes(fs.getPath("mcmod.info")), StandardCharsets.UTF_8)
str = str.replace("%%VERSION%%", project.version.toString())
Files.write(fs.getPath("mcmod.info"), str.toByteArray(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING)
fs.close()
}
fun configureManifest(manifest: Manifest) {
manifest.attributes(
"Specification-Title" to project.name,
"Specification-Version" to project.version,
"Specification-Vendor" to "OpenCubicChunks",
"Implementation-Title" to "${project.group}.${project.name.lowercase(Locale.ROOT).replace(' ', '_')}",
"Implementation-Version" to project.version,
"Implementation-Vendor" to "OpenCubicChunks",
"Implementation-Timestamp" to DateTimeFormatter.ISO_INSTANT.format(Instant.now()),
"FMLCorePlugin" to "io.github.opencubicchunks.cubicchunks.core.asm.coremod.CubicChunksCoreMod",
"TweakClass" to "org.spongepowered.asm.launch.MixinTweaker",
"TweakOrder" to "0",
"ForceLoadAsMod" to "true",
"FMLCorePluginContainsFMLMod" to "true" // workaround for mixin double-loading the mod on new forge versions
)
}
fun configureShadowJar(task: ShadowJar, classifier: String) {
task.configurations = listOf(coreShadow)
task.exclude("META-INF/MUMFREY*")
task.from(sourceSets["main"].output)
task.from(sourceSets["api"].output)
task.exclude("log4j2.xml")
task.into("/") {
from(embed)
}
task.archiveClassifier.set(classifier)
configureManifest(task.manifest)
}
//afterEvaluate {
// getByName("reobfJar").enabled = false;
//}
jar {
from(sourceSets["main"].output)
from(sourceSets["api"].output)
exclude("LICENSE.txt", "log4j2.xml")
configureManifest(manifest)
archiveClassifier.set("dev")
doLast {
substituteVersion(this as Jar)
}
}
compileJava {
options.isDeprecation = true
options.compilerArgs.add("-Xlint:unchecked")
}
javadoc {
source(sourceSets.main.get().allJava, sourceSets["api"].allJava)
(options as StandardJavadocDocletOptions).tags = listOf("reason")
}
val deobfSourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].java.srcDirs)
from(sourceSets["api"].java.srcDirs)
}
val devShadowJar by creating(ShadowJar::class) {
configureShadowJar(this, "dev-all")
doLast {
substituteVersion(this as Jar)
}
}
val deobfApiJar by creating(Jar::class) {
archiveClassifier.set("api-dev")
from(sourceSets["api"].output)
}
val deobfApiSrcJar by creating(Jar::class) {
archiveClassifier.set("api-sources")
from(sourceSets["api"].java.srcDirs)
}
val javadocApi by creating(Javadoc::class) {
source = sourceSets["api"].allJava
doFirst {
classpath = configurations.compileClasspath.get()
}
}
// gradle complains about using output of javadocApi in javadocJar and javadoc in javadocApiJar when not specifying dependencies on them
// I don't know why
val javadocJar by creating(Jar::class) {
dependsOn(javadoc, javadocApi)
archiveClassifier.set("javadoc")
from(javadoc)
}
val javadocApiJar by creating(Jar::class) {
dependsOn(javadocApi, javadoc)
archiveClassifier.set("api-javadoc")
from(javadocApi)
}
val apiJar by creating(Jar::class) {
archiveClassifier.set("api")
from(sourceSets["api"].output)
}
shadowJar {
configureShadowJar(this, "all")
doLast {
substituteVersion(this as Jar)
}
}
reobf {
create("apiJar")
create("shadowJar")
}
apiJar.finalizedBy("reobfApiJar")
shadowJar {
finalizedBy("reobfShadowJar")
}
build {
dependsOn(apiJar, deobfApiJar, deobfApiSrcJar, javadocApiJar,
shadowJar, devShadowJar, javadocJar, deobfSourcesJar)
}
afterEvaluate {
getByName("configureReobfTaskForReobfShadowJar").mustRunAfter("compileJava")
}
publish {
dependsOn(gradle.includedBuild("CubicChunksAPI").task(":publish"))
}
}
configurations {
create("mainArchives")
create("apiArchives")
}
// tasks must be before artifacts, don't change the order
artifacts {
archives(tasks["shadowJar"])
add("mainArchives", tasks["devShadowJar"])
add("mainArchives", tasks["deobfSourcesJar"])
add("mainArchives", tasks["javadocJar"])
add("apiArchives", tasks["deobfApiSrcJar"])
add("apiArchives", tasks["apiJar"])
add("apiArchives", tasks["javadocApiJar"])
add("apiArchives", tasks["deobfApiJar"])
}
publishing {
repositories {
maven {
val user = (project.properties["sonatypeUsername"] ?: System.getenv("sonatypeUsername")) as String?
val pass = (project.properties["sonatypePassword"] ?: System.getenv("sonatypePassword")) as String?
val local = user == null || pass == null
if (local) {
logger.warn("Username or password not set, publishing to local repository in build/mvnrepo/")
}
val localUrl = "$buildDir/mvnrepo"
val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
setUrl(if (local) localUrl else if (doRelease.toBoolean()) releasesRepoUrl else snapshotsRepoUrl)
if (!local) {
credentials {
username = user
password = pass
}
}
}
}
publications {
create("mod", MavenPublication::class) {
version = project.ext["mavenProjectVersion"]!!.toString()
artifactId = "cubicchunks"
artifact(tasks["shadowJar"]) {
classifier = ""
}
artifact(tasks["devShadowJar"]) {
classifier = "dev"
}
artifact(tasks["deobfSourcesJar"]) {
classifier = "sources"
}
artifact(tasks["javadocJar"]) {
classifier = "javadoc"
}
pom {
name.set(projectName)
description.set("Unlimited world height mod for Minecraft")
packaging = "jar"
url.set("https://github.com/OpenCubicChunks/CubicChunks")
scm {
connection.set("scm:git:git://github.com/OpenCubicChunks/CubicChunks.git")
developerConnection.set("scm:git:ssh://[email protected]:OpenCubicChunks/CubicChunks.git")
url.set("https://github.com/OpenCubicChunks/CubicChunks")
}
licenses {
license {
name.set("The MIT License")
url.set("http://www.tldrlegal.com/license/mit-license")
distribution.set("repo")
}
}
developers {
developer {
id.set("Barteks2x")
name.set("Barteks2x")
}
// TODO: add more developers
}
issueManagement {
system.set("github")
url.set("https://github.com/OpenCubicChunks/CubicChunks/issues")
}
}
}
}
tasks["publishModPublicationToMavenRepository"].dependsOn("shadowJar", "devShadowJar")
}
signing {
isRequired = false
// isRequired = gradle.taskGraph.hasTask("uploadArchives")
sign(configurations.archives.get())
}
license {
ext["project"] = projectName
ext["year"] = licenseYear
exclude("**/*.info")
exclude("**/package-info.java")
exclude("**/*.json")
exclude("**/*.xml")
exclude("assets/*")
exclude("io/github/opencubicchunks/cubicchunks/core/server/chunkio/async/forge/*") // Taken from forge
exclude("io/github/opencubicchunks/cubicchunks/core/lighting/phosphor/*") // Taken from Phosphor
exclude("net/optifine/**/*")
header = file("HEADER.txt")
ignoreFailures = false
strictCheck = true
mapping(mapOf("java" to "SLASHSTAR_STYLE"))
}