import org.gradle.kotlin.dsl.buildConfigField import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel import org.jetbrains.gradle.ext.runConfigurations import org.jetbrains.gradle.ext.settings import kotlin.text.replace plugins { id("org.jetbrains.gradle.plugin.idea-ext") version "1.3" id("com.gtnewhorizons.retrofuturagradle") version "2.0.2" id("com.github.gmazzo.buildconfig") version "6.0.7" id("io.freefair.lombok") version "9.1.0" } group = "dev.redstudio" version = "1.2.1" // This project adheres to [Ragnarök Versioning](https://github.com/Red-Studio-Ragnarok/Commons/blob/main/Ragnar%C3%B6k%20Versioning%20Convention.md) val id = project.name.lowercase().filter { !it.isWhitespace() } val plugin = "${project.group}.$id.asm.${project.name.filter { !it.isWhitespace() }}Plugin" val jvmCommonArgs = "-Dfile.encoding=UTF-8 -XX:+UseStringDeduplication" val mixinBooterVersion = "10.7" minecraft { mcVersion = "1.12.2" username = "Desoroxxx" extraRunJvmArguments = listOf("-Dforge.logging.console.level=debug", "-Dfml.coreMods.load=$plugin", "-Dmixin.checks.mixininterfaces=true", "-Dmixin.debug.export=true") + jvmCommonArgs.split(" ") } repositories { maven { name = "Cleanroom" url = uri("https://maven.cleanroommc.com") content { includeGroup("zone.rong") } } mavenCentral() mavenLocal() } dependencies { annotationProcessor("org.ow2.asm:asm-debug-all:5.2") annotationProcessor("com.google.guava:guava:32.1.2-jre") annotationProcessor("com.google.code.gson:gson:2.8.9") val mixinBooter: String = modUtils.enableMixins("zone.rong:mixinbooter:$mixinBooterVersion", "mixins.$id.refmap.json") as String api(mixinBooter) { isTransitive = false } annotationProcessor(mixinBooter) { isTransitive = false } } buildConfig { packageName("${project.group}.${id}") className("ProjectConstants") documentation.set("This class defines constants for ${project.name}.\n

\nThey are automatically updated by Gradle.") useJavaOutput() // Details buildConfigField("ID", id) buildConfigField("NAME", project.name) buildConfigField("VERSION", project.version.toString()) // Versions buildConfigField("MIXIN_BOOTER_VERSION", mixinBooterVersion) // Loggers buildConfigField("org.apache.logging.log4j.Logger", "LOGGER", "org.apache.logging.log4j.LogManager.getLogger(NAME)") } // Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod java { toolchain { languageVersion.set(JavaLanguageVersion.of(8)) vendor.set(JvmVendorSpec.ADOPTIUM) } if (!project.version.toString().contains("Dev")) withSourcesJar() // Generate sources jar, for releases } tasks { processResources { val expandProperties = mapOf( "version" to project.version, "name" to project.name, "id" to id ) inputs.properties(expandProperties) filesMatching("**/*.*") { val exclusions = arrayOf(".png") if (!exclusions.any { path.endsWith(it) }) expand(expandProperties) } } val processReadme by registering { val input = rootProject.file("README.md") val output = layout.buildDirectory.file("processed-readme/README.md") inputs.file(input) outputs.file(output) doLast { val content = input.readText() val firstHash = content.indexOf('#') val lastSeparator = content.lastIndexOf("---") val trimmed = when { firstHash != -1 && lastSeparator > firstHash -> content.substring(firstHash, lastSeparator) firstHash != -1 -> content.substring(firstHash) else -> content } output.get().asFile.parentFile.mkdirs() output.get().asFile.writeText(trimmed.trim()) } } withType { dependsOn(processReadme) from(processReadme.map { it.outputs.files }) from(rootProject.file("LICENSE")) from(rootProject.file("CHANGELOG.md")) manifest { attributes( "ModSide" to "BOTH", "FMLCorePlugin" to plugin, "FMLCorePluginContainsFMLMod" to "true", "ForceLoadAsMod" to "true" ) } } withType{ options.encoding = "UTF-8" options.isFork = true options.forkOptions.jvmArgs = jvmCommonArgs.split(" ") } } idea { module { inheritOutputDirs = true excludeDirs.addAll(setOf(".gradle", ".idea", "build", "gradle", "run", "gradlew", "gradlew.bat", "desktop.ini").map(::file)) } project { settings { jdkName = "1.8" languageLevel = IdeaLanguageLevel("JDK_1_8") runConfigurations { listOf("Client", "Server", "Obfuscated Client", "Obfuscated Server", "Vanilla Client", "Vanilla Server").forEach { name -> create(name, org.jetbrains.gradle.ext.Gradle::class.java) { val prefix = name.substringBefore(" ").let { if (it == "Obfuscated") "Obf" else it } val suffix = name.substringAfter(" ").takeIf { it != prefix } ?: "" taskNames = setOf("run$prefix$suffix") jvmArgs = jvmCommonArgs } } } } } }