2019-07-11 08:29:43 +08:00
|
|
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
2021-11-14 16:01:06 +08:00
|
|
|
import net.fabricmc.loom.api.LoomGradleExtensionAPI
|
2019-07-11 08:29:43 +08:00
|
|
|
import net.fabricmc.loom.task.RemapJarTask
|
|
|
|
|
2020-04-10 10:29:10 +08:00
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
maven {
|
|
|
|
name = "Fabric"
|
|
|
|
url = uri("https://maven.fabricmc.net/")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dependencies {
|
|
|
|
classpath("net.fabricmc:fabric-loom:${versions.loom}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 04:16:26 +08:00
|
|
|
applyPlatformAndCoreConfiguration(javaRelease = 17)
|
2019-07-11 08:29:43 +08:00
|
|
|
applyShadowConfiguration()
|
|
|
|
|
|
|
|
apply(plugin = "fabric-loom")
|
2020-07-16 09:48:47 +08:00
|
|
|
apply(plugin = "java-library")
|
2019-07-11 08:29:43 +08:00
|
|
|
|
2023-06-08 12:16:40 +08:00
|
|
|
val minecraftVersion = "1.20"
|
2023-06-04 13:40:08 +08:00
|
|
|
val loaderVersion = "0.14.21"
|
2019-07-11 08:29:43 +08:00
|
|
|
|
2020-06-24 02:55:49 +08:00
|
|
|
val fabricApiConfiguration: Configuration = configurations.create("fabricApi")
|
|
|
|
|
2021-11-14 16:01:06 +08:00
|
|
|
configure<LoomGradleExtensionAPI> {
|
|
|
|
accessWidenerPath.set(project.file("src/main/resources/worldedit.accesswidener"))
|
|
|
|
}
|
|
|
|
|
2020-06-24 02:55:49 +08:00
|
|
|
repositories {
|
|
|
|
maven {
|
|
|
|
name = "Fabric"
|
|
|
|
url = uri("https://maven.fabricmc.net/")
|
|
|
|
}
|
2023-06-04 13:40:08 +08:00
|
|
|
getByName("Mojang") {
|
|
|
|
content {
|
|
|
|
includeGroupByRegex("com\\.mojang\\..*")
|
|
|
|
}
|
|
|
|
}
|
2020-06-24 02:55:49 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 08:29:43 +08:00
|
|
|
dependencies {
|
2020-07-16 09:48:47 +08:00
|
|
|
"api"(project(":worldedit-core"))
|
2021-12-13 07:49:32 +08:00
|
|
|
"implementation"(platform("org.apache.logging.log4j:log4j-bom:${Versions.LOG4J}") {
|
|
|
|
because("Mojang provides Log4J")
|
2021-01-25 18:14:09 +08:00
|
|
|
})
|
2019-07-11 08:29:43 +08:00
|
|
|
|
|
|
|
"minecraft"("com.mojang:minecraft:$minecraftVersion")
|
2021-11-14 16:01:06 +08:00
|
|
|
"mappings"(project.the<LoomGradleExtensionAPI>().officialMojangMappings())
|
2020-06-29 06:51:50 +08:00
|
|
|
"modImplementation"("net.fabricmc:fabric-loader:$loaderVersion")
|
2019-07-11 08:29:43 +08:00
|
|
|
|
2020-06-24 02:55:49 +08:00
|
|
|
// [1] declare fabric-api dependency...
|
2023-05-28 14:25:53 +08:00
|
|
|
"fabricApi"("net.fabricmc.fabric-api:fabric-api:0.83.0+1.20")
|
2020-06-24 02:55:49 +08:00
|
|
|
|
2020-06-26 13:00:37 +08:00
|
|
|
// [2] Load the API dependencies from the fabric mod json...
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
|
|
val fabricModJson = file("src/main/resources/fabric.mod.json").bufferedReader().use {
|
|
|
|
groovy.json.JsonSlurper().parse(it) as Map<String, Map<String, *>>
|
|
|
|
}
|
|
|
|
val wantedDependencies = (fabricModJson["depends"] ?: error("no depends in fabric.mod.json")).keys
|
|
|
|
.filter { it == "fabric-api-base" || it.contains(Regex("v\\d$")) }
|
|
|
|
.map { "net.fabricmc.fabric-api:$it" }
|
2022-03-01 14:55:50 +08:00
|
|
|
.toSet()
|
2020-06-26 13:00:37 +08:00
|
|
|
logger.lifecycle("Looking for these dependencies:")
|
|
|
|
for (wantedDependency in wantedDependencies) {
|
|
|
|
logger.lifecycle(wantedDependency)
|
|
|
|
}
|
|
|
|
// [3] and now we resolve it to pick out what we want :D
|
2020-06-24 02:55:49 +08:00
|
|
|
val fabricApiDependencies = fabricApiConfiguration.incoming.resolutionResult.allDependencies
|
|
|
|
.onEach {
|
|
|
|
if (it is UnresolvedDependencyResult) {
|
|
|
|
throw kotlin.IllegalStateException("Failed to resolve Fabric API", it.failure)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.filterIsInstance<ResolvedDependencyResult>()
|
|
|
|
// pick out transitive dependencies
|
|
|
|
.flatMap {
|
|
|
|
it.selected.dependencies
|
|
|
|
}
|
|
|
|
// grab the requested versions
|
|
|
|
.map { it.requested }
|
|
|
|
.filterIsInstance<ModuleComponentSelector>()
|
|
|
|
// map to standard notation
|
|
|
|
.associateByTo(
|
|
|
|
mutableMapOf(),
|
|
|
|
keySelector = { "${it.group}:${it.module}" },
|
|
|
|
valueTransform = { "${it.group}:${it.module}:${it.version}" }
|
|
|
|
)
|
|
|
|
fabricApiDependencies.keys.retainAll(wantedDependencies)
|
|
|
|
// sanity check
|
|
|
|
for (wantedDep in wantedDependencies) {
|
|
|
|
check(wantedDep in fabricApiDependencies) { "Fabric API library $wantedDep is missing!" }
|
|
|
|
}
|
|
|
|
|
|
|
|
fabricApiDependencies.values.forEach {
|
2019-09-20 09:11:23 +08:00
|
|
|
"include"(it)
|
|
|
|
"modImplementation"(it)
|
|
|
|
}
|
2019-07-11 08:29:43 +08:00
|
|
|
|
2021-01-06 04:14:54 +08:00
|
|
|
// No need for this at runtime
|
|
|
|
"modCompileOnly"("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")
|
|
|
|
|
2019-09-23 04:42:26 +08:00
|
|
|
// Hook these up manually, because Fabric doesn't seem to quite do it properly.
|
2020-06-29 06:51:50 +08:00
|
|
|
"compileOnly"("net.fabricmc:sponge-mixin:${project.versions.mixin}")
|
2019-09-23 04:42:26 +08:00
|
|
|
"annotationProcessor"("net.fabricmc:sponge-mixin:${project.versions.mixin}")
|
|
|
|
"annotationProcessor"("net.fabricmc:fabric-loom:${project.versions.loom}")
|
2021-11-14 16:01:06 +08:00
|
|
|
|
|
|
|
// Silence some warnings, since apparently this isn't on the compile classpath like it should be.
|
2022-03-01 14:55:50 +08:00
|
|
|
"compileOnly"("com.google.errorprone:error_prone_annotations:2.11.0")
|
2019-07-11 08:29:43 +08:00
|
|
|
}
|
|
|
|
|
2021-11-14 13:54:21 +08:00
|
|
|
configure<BasePluginExtension> {
|
|
|
|
archivesName.set("${project.name}-mc$minecraftVersion")
|
2019-07-11 08:29:43 +08:00
|
|
|
}
|
2021-11-14 13:54:21 +08:00
|
|
|
|
2021-04-07 04:45:57 +08:00
|
|
|
configure<PublishingExtension> {
|
|
|
|
publications.named<MavenPublication>("maven") {
|
2021-11-14 13:54:21 +08:00
|
|
|
artifactId = the<BasePluginExtension>().archivesName.get()
|
|
|
|
from(components["java"])
|
2021-04-07 04:45:57 +08:00
|
|
|
}
|
|
|
|
}
|
2019-07-11 08:29:43 +08:00
|
|
|
|
|
|
|
tasks.named<Copy>("processResources") {
|
|
|
|
// this will ensure that this task is redone when the versions change.
|
|
|
|
inputs.property("version", project.ext["internalVersion"])
|
2021-05-14 13:01:45 +08:00
|
|
|
filesMatching("fabric.mod.json") {
|
|
|
|
this.expand("version" to project.ext["internalVersion"])
|
2019-07-11 08:29:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 14:05:23 +08:00
|
|
|
addJarManifest(WorldEditKind.Mod, includeClasspath = true)
|
2019-07-11 08:29:43 +08:00
|
|
|
|
|
|
|
tasks.named<ShadowJar>("shadowJar") {
|
|
|
|
archiveClassifier.set("dist-dev")
|
|
|
|
dependencies {
|
2019-10-19 15:48:49 +08:00
|
|
|
relocate("org.antlr.v4", "com.sk89q.worldedit.antlr4")
|
2019-07-11 08:29:43 +08:00
|
|
|
|
2019-10-19 15:48:49 +08:00
|
|
|
include(dependency("org.antlr:antlr4-runtime"))
|
2019-07-11 08:29:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-20 09:11:23 +08:00
|
|
|
tasks.register<RemapJarTask>("remapShadowJar") {
|
|
|
|
val shadowJar = tasks.getByName<ShadowJar>("shadowJar")
|
|
|
|
dependsOn(shadowJar)
|
2022-03-01 14:55:50 +08:00
|
|
|
inputFile.set(shadowJar.archiveFile)
|
2019-09-20 09:11:23 +08:00
|
|
|
archiveFileName.set(shadowJar.archiveFileName.get().replace(Regex("-dev\\.jar$"), ".jar"))
|
|
|
|
addNestedDependencies.set(true)
|
2019-07-11 08:29:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tasks.named("assemble").configure {
|
|
|
|
dependsOn("remapShadowJar")
|
|
|
|
}
|