2022-10-07 18:23:08 +02:00
|
|
|
import io.gitlab.jfronny.scripts.*
|
|
|
|
import net.fabricmc.loom.task.PrepareJarRemapTask
|
|
|
|
import net.fabricmc.loom.task.RemapJarTask
|
|
|
|
import org.gradle.api.publish.maven.MavenPublication
|
|
|
|
import org.gradle.api.publish.tasks.GenerateModuleMetadata
|
|
|
|
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
|
|
|
import org.gradle.api.tasks.bundling.Jar
|
|
|
|
import org.gradle.api.tasks.compile.JavaCompile
|
|
|
|
import org.gradle.kotlin.dsl.*
|
|
|
|
import java.io.File
|
|
|
|
|
2022-10-07 18:42:33 +02:00
|
|
|
plugins {
|
2022-10-07 19:05:03 +02:00
|
|
|
id("jf.earlyafterevaluate")
|
2022-10-07 18:42:33 +02:00
|
|
|
idea
|
|
|
|
`java-library`
|
|
|
|
`maven-publish`
|
2022-10-07 19:05:03 +02:00
|
|
|
id("fabric-loom")
|
2022-10-07 18:42:33 +02:00
|
|
|
id("com.github.johnrengelman.shadow")
|
|
|
|
}
|
|
|
|
|
2022-10-07 18:23:08 +02:00
|
|
|
val devlibs = File(project.buildDir, "devlibs")
|
|
|
|
|
|
|
|
// Configure loom for stricter dev env
|
|
|
|
loom {
|
|
|
|
runtimeOnlyLog4j.set(true)
|
|
|
|
splitEnvironmentSourceSets()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create testmod source set with access to main and client classpaths
|
|
|
|
sourceSets {
|
|
|
|
create("testmod") {
|
2022-10-07 18:42:33 +02:00
|
|
|
compileClasspath += sourceSets.main.get().compileClasspath
|
|
|
|
runtimeClasspath += sourceSets.main.get().runtimeClasspath
|
2022-10-07 18:23:08 +02:00
|
|
|
|
2022-10-07 18:42:33 +02:00
|
|
|
compileClasspath += sourceSets.client.get().compileClasspath
|
|
|
|
runtimeClasspath += sourceSets.client.get().runtimeClasspath
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 18:42:33 +02:00
|
|
|
val hasTestmod = !sourceSets.testmod.get().resources.isEmpty
|
2022-10-07 18:23:08 +02:00
|
|
|
|
|
|
|
// Class path groups (required to allow ultra early init)
|
|
|
|
loom {
|
|
|
|
mods {
|
|
|
|
register(name) {
|
2022-10-07 18:42:33 +02:00
|
|
|
sourceSet(sourceSets.main.get())
|
|
|
|
sourceSet(sourceSets.client.get())
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
if (hasTestmod) {
|
|
|
|
register("$name-testmod") {
|
2022-10-07 18:42:33 +02:00
|
|
|
sourceSet(sourceSets.testmod.get())
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasTestmod) {
|
|
|
|
runs {
|
|
|
|
create("testmodClient") {
|
|
|
|
client()
|
|
|
|
ideConfigGenerated(rootProject == project)
|
|
|
|
name("Testmod Client")
|
2022-10-07 18:42:33 +02:00
|
|
|
source(sourceSets.testmod.get())
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
create("testmodServer") {
|
|
|
|
server()
|
|
|
|
ideConfigGenerated(rootProject == project)
|
|
|
|
name("Testmod Server")
|
2022-10-07 18:42:33 +02:00
|
|
|
source(sourceSets.testmod.get())
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Common repositories for mods
|
|
|
|
repositories {
|
2022-11-25 14:24:06 +01:00
|
|
|
maven("https://maven.terraformersmc.com/") {
|
2022-10-07 18:23:08 +02:00
|
|
|
name = "TerraformersMC"
|
|
|
|
}
|
2022-11-25 14:24:06 +01:00
|
|
|
maven("https://maven.frohnmeyer-wds.de/artifacts") {
|
2022-10-27 22:42:57 +02:00
|
|
|
name = "JFronny"
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
mavenCentral()
|
|
|
|
mavenLocal()
|
|
|
|
}
|
|
|
|
|
2022-10-07 19:05:03 +02:00
|
|
|
// Register common dependencies
|
|
|
|
val args = extensions.create<LomExtension>("lom")
|
|
|
|
earlyAfterEvaluate {
|
|
|
|
dependencies {
|
|
|
|
minecraft("com.mojang:minecraft:${args.minecraftVersion.get()}")
|
|
|
|
if (args.yarnBuild != null) mappings("net.fabricmc:yarn:${args.minecraftVersion.get()}+${args.yarnBuild}:v2")
|
|
|
|
else loom.officialMojangMappings()
|
|
|
|
modImplementation("net.fabricmc:fabric-loader:${args.loaderVersion.get()}")
|
|
|
|
|
|
|
|
testmodImplementation(sourceSets.main.get().output)
|
|
|
|
testmodImplementation(sourceSets.client.get().output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 18:23:08 +02:00
|
|
|
// Mark normal jars as -dev
|
2022-10-07 18:42:33 +02:00
|
|
|
tasks.jar.get().archiveClassifier.set("dev")
|
2022-10-07 18:23:08 +02:00
|
|
|
|
|
|
|
// Used for referencing the unremapped jars of other projects
|
2022-12-13 23:07:05 +01:00
|
|
|
artifacts.add(configurations.create("dev").name, tasks.jar) {
|
2022-10-07 18:23:08 +02:00
|
|
|
type = "jar"
|
2022-12-13 23:07:05 +01:00
|
|
|
builtBy(tasks.jar)
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// configure the shadow task to not shadow by default and output to builds/devlibs
|
|
|
|
tasks.shadowJar {
|
2022-12-13 23:07:05 +01:00
|
|
|
// get injectCompiledConfig task if present (-> LibJF) or use normal jar task
|
|
|
|
val inputTask = providers.provider { tasks.findByName("injectCompiledConfig") as Jar? }.orElse(tasks.jar)
|
2022-10-07 18:23:08 +02:00
|
|
|
dependsOn(inputTask)
|
|
|
|
configurations.clear()
|
2022-12-13 23:07:05 +01:00
|
|
|
from(project.configurations.shadow, inputTask)
|
2022-10-07 18:23:08 +02:00
|
|
|
archiveClassifier.set("shadow")
|
|
|
|
destinationDirectory.set(devlibs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate sources jar to publish for better debugging with dependents
|
|
|
|
java {
|
|
|
|
withSourcesJar()
|
|
|
|
}
|
|
|
|
|
|
|
|
// attempt to allow reproducible builds by removing unneeded metadata from jars
|
2022-12-13 23:07:05 +01:00
|
|
|
tasks.withType<AbstractArchiveTask> {
|
2022-10-07 18:23:08 +02:00
|
|
|
isPreserveFileTimestamps = false
|
|
|
|
isReproducibleFileOrder = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate remapped jar without JiJ'd dependencies for maven publish
|
|
|
|
val remapMavenJar by tasks.registering(RemapJarTask::class) {
|
2022-12-13 23:07:05 +01:00
|
|
|
dependsOn(tasks.shadowJar)
|
|
|
|
inputFile.set(tasks.shadowJar.get().archiveFile)
|
2022-10-07 18:23:08 +02:00
|
|
|
archiveFileName.set("${archiveBaseName.get()}-${project.versionS}-maven.jar")
|
|
|
|
addNestedDependencies.set(false)
|
|
|
|
}
|
2022-12-13 23:07:05 +01:00
|
|
|
tasks.assemble { dependsOn(remapMavenJar) }
|
2022-10-07 18:23:08 +02:00
|
|
|
|
|
|
|
// configure remapJar to use the output of shadow
|
|
|
|
tasks.remapJar {
|
2022-12-13 23:07:05 +01:00
|
|
|
dependsOn(tasks.shadowJar)
|
|
|
|
inputFile.set(tasks.shadowJar.get().archiveFile)
|
2022-10-07 18:23:08 +02:00
|
|
|
archiveFileName.set("${archiveBaseName.get()}-${project.versionS}.jar")
|
|
|
|
}
|
|
|
|
|
|
|
|
// fill in mod version
|
|
|
|
tasks.processResources {
|
|
|
|
filesMatching("fabric.mod.json") {
|
|
|
|
expand(mapOf("version" to project.versionS))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// publish sources jar and remapped jar without JiJ'd deps
|
|
|
|
publishing {
|
|
|
|
publications {
|
|
|
|
create<MavenPublication>("lom") {
|
|
|
|
from(components["java"])
|
2022-12-13 23:07:05 +01:00
|
|
|
setArtifacts(listOf(remapMavenJar, tasks.sourcesJar))
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-13 23:07:05 +01:00
|
|
|
tasks.publish { dependsOn(tasks.build) }
|
|
|
|
tasks.deployDebug.dependsOn(tasks.publish)
|
2022-10-07 18:23:08 +02:00
|
|
|
|
|
|
|
// create testmodInclude configuration
|
|
|
|
val testmodIncludeConfiguration = configurations.create("testmodInclude")
|
|
|
|
|
|
|
|
if (hasTestmod) {
|
|
|
|
// generate jar from testmod source set
|
|
|
|
val testmodJar by tasks.registering(Jar::class) {
|
2022-10-07 18:42:33 +02:00
|
|
|
from(sourceSets.testmod.get().output)
|
2022-10-07 18:23:08 +02:00
|
|
|
destinationDirectory.set(devlibs)
|
|
|
|
archiveClassifier.set("testmod")
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEvaluate {
|
|
|
|
// remap configuration for outputting usable testmod jar
|
|
|
|
val remapTestmodJar by tasks.registering(RemapJarTask::class) {
|
2022-12-13 23:07:05 +01:00
|
|
|
dependsOn(testmodJar)
|
|
|
|
inputFile.set(testmodJar.get().archiveFile)
|
2022-10-07 18:23:08 +02:00
|
|
|
archiveClassifier.set("testmod")
|
|
|
|
// add nested jars from testmodInclude
|
|
|
|
addNestedDependencies.set(true)
|
|
|
|
nestedJars.setFrom(*testmodIncludeConfiguration.files.toTypedArray())
|
|
|
|
}
|
2022-12-13 23:07:05 +01:00
|
|
|
tasks.assemble { dependsOn(remapTestmodJar) }
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEvaluate {
|
|
|
|
// from fabric-example-mod, enforces modern java
|
|
|
|
tasks.withType<JavaCompile>().configureEach {
|
|
|
|
options.encoding = "UTF-8"
|
|
|
|
options.release.set(17)
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise we can't easily overwrite the artifacts to publish while keeping dependency metadata
|
|
|
|
tasks.withType<GenerateModuleMetadata> {
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix prepareRemapJar
|
|
|
|
// Finds remapJar tasks and the corresponding prepareRemapJar tasks and ensures the dependencies of remapJar are run before prepareRemapJar
|
|
|
|
// This ensures the input files exist when the task is run
|
|
|
|
tasks.configureEach {
|
|
|
|
if (this is RemapJarTask) {
|
|
|
|
this.dependsOn.filterIsInstance<PrepareJarRemapTask>().forEach { prepareTask ->
|
2022-12-13 23:07:05 +01:00
|
|
|
prepareTask.dependsOn(*this.dependsOn.filterNot { it == prepareTask }.toTypedArray())
|
2022-10-07 18:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|