almostunified/build.gradle.kts

247 lines
7.9 KiB
Text
Raw Normal View History

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
2023-06-14 05:48:49 -04:00
val autoServiceVersion: String by project
val parchmentVersion: String by project
2023-07-28 18:59:02 -04:00
val fabricApiVersion: String by project
val forgeVersion: 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
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.+"
2023-07-28 18:59:02 -04:00
id("dev.architectury.loom") version "1.3.+" apply false
id("io.github.juuxel.loom-vineflower") version "1.11.0" 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
}
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"
options.release.set(17)
}
2023-07-28 18:59:02 -04:00
withType<GenerateModuleMetadata> {
enabled = false
}
2022-05-31 10:50:46 -04:00
}
extensions.configure<JavaPluginExtension> {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
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")
2023-07-28 18:59:02 -04:00
apply(plugin = "io.github.juuxel.loom-vineflower")
2023-02-01 14:43:30 -05:00
apply(plugin = "maven-publish")
2023-07-28 18:59:02 -04:00
base {
archivesName.set("$modId-${project.name.lowercase()}")
version = "$minecraftVersion-$modVersion"
}
repositories {
maven("https://maven.parchmentmc.org") // Parchment
maven("https://maven.shedaniel.me") // REI
maven("https://maven.blamejared.com/") // JEI
mavenLocal()
}
2023-02-01 14:43:30 -05:00
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom")
loom.silentMojangMappingsLicense()
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()
2023-07-28 18:59:02 -04:00
parchment("org.parchmentmc.data:parchment-$minecraftVersion:$parchmentVersion@zip")
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
*/
2023-06-14 05:48:49 -04:00
compileOnly("com.google.auto.service:auto-service:$autoServiceVersion")
annotationProcessor("com.google.auto.service:auto-service:$autoServiceVersion")
2023-02-01 14:43:30 -05:00
}
2023-06-14 05:48:49 -04:00
tasks {
/**
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 {
val resourceTargets = listOf("META-INF/mods.toml", "pack.mcmeta", "fabric.mod.json")
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,
"forgeVersion" to forgeVersion,
2023-07-28 18:59:02 -04:00
// use major version for FML only because wrong Forge version error message
// is way better than FML error message
"forgeFMLVersion" to forgeVersion.substringBefore("."),
2023-06-14 05:48:49 -04:00
"jeiVersion" to jeiVersion,
"reiVersion" to reiVersion,
"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"])
}
}
/**
* 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")
extensions.configure<LoomGradleExtensionAPI> {
runs {
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}"
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")
}
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-05-31 10:50:46 -04:00
}
}