Plex-FAWE/worldedit-fabric/build.gradle.kts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

166 lines
5.3 KiB
Plaintext
Raw Normal View History

2019-07-11 00:29:43 +00:00
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.LoomGradleExtension
2019-07-11 00:29:43 +00:00
import net.fabricmc.loom.task.RemapJarTask
buildscript {
repositories {
mavenCentral()
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
}
dependencies {
classpath("net.fabricmc:fabric-loom:${versions.loom}")
}
}
2019-07-11 00:29:43 +00:00
applyPlatformAndCoreConfiguration()
applyShadowConfiguration()
apply(plugin = "fabric-loom")
2020-08-14 19:29:15 +00:00
apply(plugin = "java-library")
2019-07-11 00:29:43 +00:00
configure<LoomGradleExtension> {
accessWidener("src/main/resources/worldedit.accesswidener")
}
val minecraftVersion = "1.16.3"
val yarnMappings = "1.16.3+build.1:v2"
val loaderVersion = "0.10.8"
2019-07-11 00:29:43 +00:00
configurations.all {
resolutionStrategy {
force("com.google.guava:guava:21.0")
}
}
val fabricApiConfiguration: Configuration = configurations.create("fabricApi")
repositories {
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
}
2019-07-11 00:29:43 +00:00
dependencies {
"api"(project(":worldedit-core"))
"implementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
2019-07-11 00:29:43 +00:00
"minecraft"("com.mojang:minecraft:$minecraftVersion")
"mappings"("net.fabricmc:yarn:$yarnMappings")
"modImplementation"("net.fabricmc:fabric-loader:$loaderVersion")
// [1] declare fabric-api dependency...
"fabricApi"("net.fabricmc.fabric-api:fabric-api:0.29.3+1.16")
// [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" }
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
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 01:11:23 +00:00
"include"(it)
"modImplementation"(it)
}
2019-07-11 00:29:43 +00:00
// No need for this at runtime
"modCompileOnly"("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")
// Hook these up manually, because Fabric doesn't seem to quite do it properly.
"compileOnly"("net.fabricmc:sponge-mixin:${project.versions.mixin}")
"annotationProcessor"("net.fabricmc:sponge-mixin:${project.versions.mixin}")
"annotationProcessor"("net.fabricmc:fabric-loom:${project.versions.loom}")
2019-07-11 00:29:43 +00:00
}
configure<BasePluginConvention> {
archivesBaseName = "$archivesBaseName-mc$minecraftVersion"
}
tasks.named<Copy>("processResources") {
// this will ensure that this task is redone when the versions change.
inputs.property("version", project.ext["internalVersion"])
from(sourceSets["main"].resources.srcDirs) {
include("fabric.mod.json")
expand("version" to project.ext["internalVersion"])
}
// copy everything else except the mod json
from(sourceSets["main"].resources.srcDirs) {
exclude("fabric.mod.json")
}
}
addJarManifest(includeClasspath = true)
2019-07-11 00:29:43 +00:00
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("dist-dev")
dependencies {
relocate("org.slf4j", "com.sk89q.worldedit.slf4j")
relocate("org.apache.logging.slf4j", "com.sk89q.worldedit.log4jbridge")
2019-10-19 07:48:49 +00:00
relocate("org.antlr.v4", "com.sk89q.worldedit.antlr4")
2019-07-11 00:29:43 +00:00
include(dependency("org.slf4j:slf4j-api"))
include(dependency("org.apache.logging.log4j:log4j-slf4j-impl"))
2019-10-19 07:48:49 +00:00
include(dependency("org.antlr:antlr4-runtime"))
2019-07-11 00:29:43 +00:00
}
}
tasks.register<Jar>("deobfJar") {
from(sourceSets["main"].output)
archiveClassifier.set("dev")
}
artifacts {
add("archives", tasks.named("deobfJar"))
}
2019-09-20 01:11:23 +00:00
tasks.register<RemapJarTask>("remapShadowJar") {
val shadowJar = tasks.getByName<ShadowJar>("shadowJar")
dependsOn(shadowJar)
input.set(shadowJar.archiveFile)
archiveFileName.set(shadowJar.archiveFileName.get().replace(Regex("-dev\\.jar$"), ".jar"))
addNestedDependencies.set(true)
remapAccessWidener.set(true)
2019-07-11 00:29:43 +00:00
}
tasks.named("assemble").configure {
dependsOn("remapShadowJar")
}