2023-02-01 14:43:30 -05:00
|
|
|
@file:Suppress("UnstableApiUsage")
|
2022-05-31 10:50:46 -04:00
|
|
|
|
2023-02-01 14:43:30 -05:00
|
|
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
|
|
|
import net.fabricmc.loom.api.LoomGradleExtensionAPI
|
|
|
|
import net.fabricmc.loom.task.RemapJarTask
|
|
|
|
|
|
|
|
val license: String by project
|
|
|
|
val minecraftVersion: String by project
|
|
|
|
val modVersion: String by project
|
2022-05-31 10:50:46 -04:00
|
|
|
val modId: String by project
|
|
|
|
val modName: String by project
|
|
|
|
val modDescription: String by project
|
2023-02-01 14:43:30 -05:00
|
|
|
val modAuthor: String by project
|
2024-08-22 09:06:58 -04:00
|
|
|
val modPackage: String by project
|
2023-06-14 05:48:49 -04:00
|
|
|
val autoServiceVersion: String by project
|
2024-08-22 09:06:58 -04:00
|
|
|
val junitVersion: String by project
|
2023-06-14 05:48:49 -04:00
|
|
|
val parchmentVersion: String by project
|
2023-07-28 18:59:02 -04:00
|
|
|
val fabricApiVersion: String by project
|
2024-08-22 09:06:58 -04:00
|
|
|
val neoforgeVersion: String by project
|
2023-04-18 17:55:06 -04:00
|
|
|
val jeiVersion: String by project
|
2023-02-01 14:43:30 -05:00
|
|
|
val reiVersion: String by project
|
2024-08-22 09:06:58 -04:00
|
|
|
val emiVersion: String by project
|
2023-07-28 18:59:02 -04:00
|
|
|
val githubRepo: String by project
|
|
|
|
val githubUser: String by project
|
2022-05-31 10:50:46 -04:00
|
|
|
|
|
|
|
plugins {
|
2023-08-05 18:36:18 -04:00
|
|
|
id("architectury-plugin") version "3.4.+"
|
2024-08-22 09:06:58 -04:00
|
|
|
id("dev.architectury.loom") version "1.7.+" apply false
|
2023-06-14 05:48:49 -04:00
|
|
|
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
|
2023-07-28 18:59:02 -04:00
|
|
|
java
|
|
|
|
`maven-publish`
|
2022-05-31 10:50:46 -04:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:43:30 -05:00
|
|
|
architectury {
|
|
|
|
minecraft = minecraftVersion
|
|
|
|
}
|
2022-09-24 14:05:47 -04:00
|
|
|
|
2023-07-28 18:59:02 -04:00
|
|
|
/**
|
|
|
|
* configurations for all projects including the root project
|
|
|
|
*/
|
2023-02-01 14:43:30 -05:00
|
|
|
allprojects {
|
|
|
|
apply(plugin = "java")
|
|
|
|
|
|
|
|
tasks {
|
|
|
|
withType<JavaCompile> {
|
|
|
|
options.encoding = "UTF-8"
|
2024-08-22 09:06:58 -04:00
|
|
|
options.release.set(21)
|
2022-07-29 16:45:44 -04:00
|
|
|
}
|
2023-07-28 18:59:02 -04:00
|
|
|
|
|
|
|
withType<GenerateModuleMetadata> {
|
|
|
|
enabled = false
|
|
|
|
}
|
2022-05-31 10:50:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
extensions.configure<JavaPluginExtension> {
|
2024-08-22 09:06:58 -04:00
|
|
|
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
2022-05-31 10:50:46 -04:00
|
|
|
withSourcesJar()
|
|
|
|
}
|
2023-02-01 14:43:30 -05:00
|
|
|
}
|
2022-05-31 10:50:46 -04:00
|
|
|
|
2023-07-28 18:59:02 -04:00
|
|
|
/**
|
|
|
|
* configurations for all projects except the root project
|
|
|
|
*/
|
2023-02-01 14:43:30 -05:00
|
|
|
subprojects {
|
2023-07-28 18:59:02 -04:00
|
|
|
apply(plugin = "architectury-plugin")
|
2023-02-01 14:43:30 -05:00
|
|
|
apply(plugin = "dev.architectury.loom")
|
|
|
|
apply(plugin = "maven-publish")
|
|
|
|
|
2023-07-28 18:59:02 -04:00
|
|
|
base {
|
|
|
|
archivesName.set("$modId-${project.name.lowercase()}")
|
|
|
|
version = "$minecraftVersion-$modVersion"
|
|
|
|
}
|
|
|
|
|
|
|
|
repositories {
|
2024-08-22 09:06:58 -04:00
|
|
|
maven("https://maven.neoforged.net/releases")
|
2023-07-28 18:59:02 -04:00
|
|
|
maven("https://maven.parchmentmc.org") // Parchment
|
|
|
|
maven("https://maven.shedaniel.me") // REI
|
|
|
|
maven("https://maven.blamejared.com/") // JEI
|
2024-08-22 09:06:58 -04:00
|
|
|
maven("https://maven.terraformersmc.com/") // EMI
|
2023-07-28 18:59:02 -04:00
|
|
|
mavenLocal()
|
|
|
|
}
|
2023-02-01 14:43:30 -05:00
|
|
|
|
|
|
|
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom")
|
|
|
|
loom.silentMojangMappingsLicense()
|
2024-08-22 09:06:58 -04:00
|
|
|
loom.createRemapConfigurations(sourceSets.getByName("test")) // create test implementations that allow remapping
|
2023-02-01 14:43:30 -05:00
|
|
|
|
|
|
|
dependencies {
|
|
|
|
/**
|
2023-07-28 18:59:02 -04:00
|
|
|
* Minecraft
|
|
|
|
* Kotlin accessor methods are not generated in this gradle
|
|
|
|
* they can be accessed through quoted names instead
|
2023-02-01 14:43:30 -05:00
|
|
|
*/
|
|
|
|
"minecraft"("com.mojang:minecraft:$minecraftVersion")
|
2023-06-14 05:48:49 -04:00
|
|
|
"mappings"(loom.layered {
|
|
|
|
officialMojangMappings()
|
2024-09-27 13:38:55 -04:00
|
|
|
parchment("org.parchmentmc.data:parchment-1.21:$parchmentVersion@zip") // TODO: replace on parchment update
|
2023-06-14 05:48:49 -04:00
|
|
|
})
|
2023-02-01 14:43:30 -05:00
|
|
|
|
|
|
|
/**
|
2023-07-28 18:59:02 -04:00
|
|
|
* non-Minecraft dependencies
|
2023-02-01 14:43:30 -05:00
|
|
|
*/
|
2024-08-22 09:06:58 -04:00
|
|
|
compileOnly(testCompileOnly("com.google.auto.service:auto-service:$autoServiceVersion")!!)
|
|
|
|
annotationProcessor(testAnnotationProcessor("com.google.auto.service:auto-service:$autoServiceVersion")!!)
|
|
|
|
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
|
2023-02-01 14:43:30 -05:00
|
|
|
}
|
|
|
|
|
2023-06-14 05:48:49 -04:00
|
|
|
tasks {
|
2024-08-22 09:06:58 -04:00
|
|
|
val apiJar = register<Jar>("apiJar") {
|
|
|
|
val remapJar = named<RemapJarTask>("remapJar")
|
|
|
|
archiveClassifier.set("api")
|
|
|
|
dependsOn(remapJar)
|
|
|
|
from(zipTree(remapJar.get().archiveFile))
|
|
|
|
include(modPackage.replace('.', '/') + "/api/**")
|
|
|
|
}
|
|
|
|
|
|
|
|
build {
|
|
|
|
dependsOn(apiJar)
|
|
|
|
}
|
|
|
|
|
2023-06-14 05:48:49 -04:00
|
|
|
/**
|
2023-07-28 18:59:02 -04:00
|
|
|
* resource processing for defined targets
|
|
|
|
* will replace `${key}` with the specified values from the map below
|
2023-06-14 05:48:49 -04:00
|
|
|
*/
|
|
|
|
processResources {
|
2024-08-22 09:06:58 -04:00
|
|
|
val resourceTargets = listOf("META-INF/neoforge.mods.toml", "fabric.mod.json", "pack.mcmeta")
|
2023-06-14 05:48:49 -04:00
|
|
|
|
|
|
|
val replaceProperties = mapOf(
|
|
|
|
"version" to project.version as String,
|
|
|
|
"license" to license,
|
|
|
|
"modId" to modId,
|
|
|
|
"modName" to modName,
|
|
|
|
"minecraftVersion" to minecraftVersion,
|
|
|
|
"modAuthor" to modAuthor,
|
|
|
|
"modDescription" to modDescription,
|
|
|
|
"fabricApiVersion" to fabricApiVersion,
|
2024-08-22 09:06:58 -04:00
|
|
|
"neoforgeVersion" to neoforgeVersion,
|
2023-06-14 05:48:49 -04:00
|
|
|
"jeiVersion" to jeiVersion,
|
|
|
|
"reiVersion" to reiVersion,
|
2024-08-22 09:06:58 -04:00
|
|
|
"emiVersion" to emiVersion,
|
2023-06-14 05:48:49 -04:00
|
|
|
"githubUser" to githubUser,
|
|
|
|
"githubRepo" to githubRepo
|
|
|
|
)
|
|
|
|
|
2023-07-28 18:59:02 -04:00
|
|
|
println("[Process Resources] Replacing resource properties for project '${project.name}': ")
|
2023-06-14 05:48:49 -04:00
|
|
|
replaceProperties.forEach { (key, value) -> println("\t -> $key = $value") }
|
|
|
|
|
|
|
|
inputs.properties(replaceProperties)
|
|
|
|
filesMatching(resourceTargets) {
|
|
|
|
expand(replaceProperties)
|
|
|
|
}
|
2023-02-01 14:43:30 -05:00
|
|
|
}
|
|
|
|
}
|
2023-07-28 18:59:02 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maven publishing
|
|
|
|
*/
|
|
|
|
publishing {
|
|
|
|
publications {
|
|
|
|
val mpm = project.properties["maven-publish-method"] as String
|
|
|
|
println("[Publish Task] Publishing method for project '${project.name}': $mpm")
|
|
|
|
register(mpm, MavenPublication::class) {
|
|
|
|
artifactId = base.archivesName.get()
|
|
|
|
from(components["java"])
|
2024-08-22 09:06:58 -04:00
|
|
|
|
|
|
|
val apiJarTask = tasks.named<Jar>("apiJar")
|
|
|
|
artifact(apiJarTask) {
|
|
|
|
classifier = "api"
|
|
|
|
}
|
2023-07-28 18:59:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* information on how to set up publishing
|
|
|
|
* https://docs.gradle.org/current/userguide/publishing_maven.html
|
|
|
|
*/
|
|
|
|
repositories {
|
|
|
|
maven("file://${System.getenv("local_maven")}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* disabling the runtime transformer from Architectury
|
|
|
|
* if the runtime transformer should be enabled again, remove this block and
|
|
|
|
* add the following to the respective subproject:
|
|
|
|
*
|
|
|
|
* configurations {
|
|
|
|
* "developmentFabric" { extendsFrom(configurations["common"]) }
|
|
|
|
* "developmentForge" { extendsFrom(configurations["common"]) }
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
architectury {
|
|
|
|
compileOnly()
|
|
|
|
}
|
2023-02-01 14:43:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-28 18:59:02 -04:00
|
|
|
* configurations for all subprojects except the common project
|
2023-02-01 14:43:30 -05:00
|
|
|
*/
|
|
|
|
subprojects {
|
|
|
|
if (project.path == ":Common") {
|
|
|
|
return@subprojects
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(plugin = "com.github.johnrengelman.shadow")
|
|
|
|
|
2024-08-22 09:06:58 -04:00
|
|
|
/**
|
|
|
|
* add the outputs of the common test source set to the test source set classpath
|
|
|
|
*/
|
|
|
|
sourceSets.named("test") {
|
|
|
|
val cst = project(":Common").sourceSets.getByName("test")
|
|
|
|
this.compileClasspath += cst.output
|
|
|
|
this.runtimeClasspath += cst.output
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:43:30 -05:00
|
|
|
extensions.configure<LoomGradleExtensionAPI> {
|
|
|
|
runs {
|
2024-08-22 09:06:58 -04:00
|
|
|
create("test_client") {
|
|
|
|
name("Testmod Client")
|
|
|
|
client()
|
|
|
|
source(sourceSets.test.get())
|
|
|
|
property("fabric-api.gametest", "true")
|
|
|
|
property("neoforge.gameTestServer", "true")
|
|
|
|
property("neoforge.enabledGameTestNamespaces", "testmod")
|
|
|
|
property("$modId.gametest.testPackages", "testmod.*")
|
|
|
|
property("$modId.configDir", rootProject.projectDir.toPath().resolve("testmod_configs").toString())
|
|
|
|
}
|
|
|
|
|
|
|
|
create("gametest") {
|
|
|
|
name("Gametest")
|
|
|
|
server()
|
|
|
|
source(sourceSets.test.get())
|
|
|
|
property("fabric-api.gametest", "true")
|
|
|
|
property("neoforge.gameTestServer", "true")
|
|
|
|
property("neoforge.enabledGameTestNamespaces", "testmod")
|
|
|
|
property("$modId.gametest.testPackages", "testmod.*")
|
|
|
|
property("$modId.configDir", rootProject.projectDir.toPath().resolve("testmod_configs").toString())
|
|
|
|
}
|
|
|
|
|
2023-06-14 05:48:49 -04:00
|
|
|
forEach {
|
2023-07-28 18:59:02 -04:00
|
|
|
val dir = "../run/${project.name.lowercase()}_${it.environment}"
|
2023-09-21 17:50:44 -04:00
|
|
|
println("[Run Config] ${project.name} '${it.name}' directory: $dir")
|
2023-07-28 18:59:02 -04:00
|
|
|
it.runDir(dir)
|
|
|
|
// allows DCEVM hot-swapping when using the JBR (https://github.com/JetBrains/JetBrainsRuntime)
|
2023-02-01 14:43:30 -05:00
|
|
|
it.vmArgs("-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition")
|
2022-09-06 12:00:29 -04:00
|
|
|
}
|
2022-05-31 10:50:46 -04:00
|
|
|
}
|
2023-02-01 14:43:30 -05:00
|
|
|
|
|
|
|
/**
|
2023-07-28 18:59:02 -04:00
|
|
|
* "main" matches the default mod name
|
|
|
|
* since `compileOnly()` is being used in Architectury, the local mods for the
|
|
|
|
* loaders need to be set up too
|
|
|
|
* otherwise, they won't recognize :Common.
|
2023-02-01 14:43:30 -05:00
|
|
|
*/
|
|
|
|
with(mods.maybeCreate("main")) {
|
|
|
|
fun Project.sourceSets() = extensions.getByName<SourceSetContainer>("sourceSets")
|
|
|
|
sourceSet(sourceSets().getByName("main"))
|
|
|
|
sourceSet(project(":Common").sourceSets().getByName("main"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val common by configurations.creating
|
2023-07-28 18:59:02 -04:00
|
|
|
val shadowCommon by configurations.creating // don't use shadow from the plugin, IDEA shouldn't index this
|
2023-02-01 14:43:30 -05:00
|
|
|
configurations {
|
|
|
|
"compileClasspath" { extendsFrom(common) }
|
|
|
|
"runtimeClasspath" { extendsFrom(common) }
|
|
|
|
}
|
|
|
|
|
|
|
|
with(components["java"] as AdhocComponentWithVariants) {
|
|
|
|
withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() }
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks {
|
|
|
|
named<ShadowJar>("shadowJar") {
|
|
|
|
exclude("architectury.common.json")
|
|
|
|
configurations = listOf(shadowCommon)
|
|
|
|
archiveClassifier.set("dev-shadow")
|
2022-09-24 14:05:47 -04:00
|
|
|
}
|
2023-02-01 14:43:30 -05:00
|
|
|
|
|
|
|
named<RemapJarTask>("remapJar") {
|
|
|
|
inputFile.set(named<ShadowJar>("shadowJar").get().archiveFile)
|
|
|
|
dependsOn("shadowJar")
|
2023-06-14 05:48:49 -04:00
|
|
|
archiveClassifier.set(null as String?)
|
2023-08-05 18:36:18 -04:00
|
|
|
injectAccessWidener.set(true)
|
2023-02-01 14:43:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
named<Jar>("jar") {
|
|
|
|
archiveClassifier.set("dev")
|
|
|
|
}
|
|
|
|
|
|
|
|
named<Jar>("sourcesJar") {
|
|
|
|
val commonSources = project(":Common").tasks.named<Jar>("sourcesJar")
|
|
|
|
dependsOn(commonSources)
|
|
|
|
from(commonSources.get().archiveFile.map { zipTree(it) })
|
|
|
|
archiveClassifier.set("sources")
|
2022-09-24 14:05:47 -04:00
|
|
|
}
|
2022-05-31 10:50:46 -04:00
|
|
|
}
|
|
|
|
}
|