import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.modrinth.minotaur.request.VersionType buildscript { dependencies { classpath("com.guardsquare:proguard-gradle:[7.1.0-beta3, 7.2[") { exclude("com.android.tools.build") } } } plugins { kotlin("jvm") version "1.5.0" id("com.github.johnrengelman.shadow") version "6.1.0" apply false id("architectury-plugin") version "[3.0.100, 3.3[" id("dev.architectury.loom") version "0.7.2.110" apply false id("com.github.ben-manes.versions") version "0.38.0" id("net.kyori.indra.git") version "2.0.4" id("com.modrinth.minotaur") version "1.2.1" } group = "fr.username404" version = "0.0.1" val groupAndName = "${rootProject.group}.${rootProject.name.toLowerCase()}" architectury { minecraft = rootProject.property("minecraft") as String } val kotlinX: String = "org.jetbrains.kotlinx" subprojects { group = rootProject.group.toString() lateinit var mappingsDep: Dependency apply(plugin = "dev.architectury.loom") extensions.configure("loom") { mappingsDep = officialMojangMappings() silentMojangMappingsLicense() mixinConfig("snowygui-mixins.json") refmapName = "snowygui-common-refmap.json" } apply(plugin = "com.github.johnrengelman.shadow") val shadowC by configurations.creating repositories { maven(url = "https://jitpack.io"); mavenCentral() } dependencies { implementation("$kotlinX:kotlinx-coroutines-core:1.5.0-RC") listOf( "$kotlinX:kotlinx-datetime:0.2.0", "com.typesafe:config:1.4.1", "io.github.config4k:config4k:0.4.2", "org.jetbrains:annotations:20.1.0" ).forEach { implementation(it); shadowC(it) { isTransitive = false; } } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "mappings"(mappingsDep) } tasks { apply(plugin = "net.kyori.indra.git") withType(Jar::class) { from("$rootDir/LICENSE.txt") indraGit.applyVcsInformationToManifest(manifest) archiveBaseName.set("${rootProject.name}-${rootProject.version}") } withType(ShadowJar::class) { this.configurations = listOf(shadowC) relocate("kotlinx.datetime", "${rootProject.group}.datetime") relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs") relocate("javassist", "${rootProject.group}.javassist") relocate("org.reflections8", "${rootProject.group}.reflectionlib") relocate("com.typesafe.config", "${rootProject.group}.typesafe.config") relocate("io.github.config4k", "${rootProject.group}.config4k") relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc") exclude("**/*.kotlin_metadata") exclude("**/*.kotlin_builtins") exclude("META-INF/maven/**/*") archiveClassifier.set("shadow-${this@subprojects.name}") } val shadowJar = getByName("shadowJar") as ShadowJar val shrinkJar = register("shrinkJar", proguard.gradle.ProGuardTask::class) { group = this@subprojects.group as String val dictionariesDir = "$rootDir/obfuscation" injars(shadowJar) outjars("$buildDir/shrinkedJar/${shadowJar.outputs.files.singleFile.name}") keep("class $group.snowygui.mixins.* { * ; }") keep("class $group.snowygui.fabric.**") keep("class $group.snowygui.forge.**") keepnames("class $group.snowygui.Snowy") keepnames("class $group.snowygui.gui.feature.Macro { ; }") keep("class $group.snowygui.gui.feature.* { public static *** INSTANCE; }") keepclassmembers("class $group.snowygui.** { public protected ; }") keepattributes("*Annotation*, Signature, InnerClasses, EnclosingMethod, MethodParameters, Synthetic, Exceptions") obfuscationdictionary("$dictionariesDir/dictionary.txt") classobfuscationdictionary("$dictionariesDir/classdictionary.txt") packageobfuscationdictionary("$dictionariesDir/packagesdictionary.txt") flattenpackagehierarchy("$group.snowygui") allowaccessmodification() adaptclassstrings() "$group.**".also { dontnote(it); dontwarn(it) } dontwarn("kotlinx.serialization.**") val homeDir = System.getProperty("java.home") as String doFirst { libraryjars(configurations.compileClasspath.get().filterNot { file -> shadowC.contains(file) }) } if (JavaVersion.current().isJava9Compatible) { val jmodsLocations = setOf( "$homeDir/jmods/java.base.jmod", "$homeDir/jmods/java.desktop.jmod", "$homeDir/jmods/java.instrument.jmod" ) if (jmodsLocations.all { !file(it).exists() }) throw GradleException("Jmods appear to be missing, please make sure that jmods are installed.") else jmodsLocations.forEach { libraryjars(it) } } else libraryjars("$homeDir/lib/rt.jar") // Note: dontpreverify() should NOT be used, it will cause errors at runtime useuniqueclassmembernames() optimizationpasses(4) overloadaggressively() mergeinterfacesaggressively() } withType(net.fabricmc.loom.task.RemapJarTask::class) { dependsOn(shrinkJar) val shrinkedJar = shrinkJar.get().outJarFileCollection.singleFile archiveBaseName.set(shadowJar.archiveBaseName) archiveClassifier.set(this@subprojects.name) input.set(shrinkedJar) if (!archiveFileName.get().contains("common")) destinationDirectory.set(file("$rootDir/remappedJars")) } } } val javaVer: String = "8" val kotlinVer = rootProject.property("kotlin_stdlib_version").toString() + ".0" val mcBase: String = rootProject.architectury.minecraft.dropLast(2) allprojects { /** configurations.all { resolutionStrategy { eachDependency { if (requested.group == "org.jetbrains.kotlin" && requested.name.contains("stdlib") && (requested.version != kotlinVer)) { useVersion(kotlinVer) } } } } **/ apply(plugin = "java") apply(plugin = "org.jetbrains.kotlin.jvm") apply(plugin = "architectury-plugin") java { sourceCompatibility = JavaVersion.VERSION_11 } dependencies { implementation(kotlin("stdlib-jdk8", kotlinVer)) implementation(kotlin("reflect", kotlinVer)) annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.3.0") { listOf("byte-buddy", "byte-buddy-agent").forEach { exclude(module = it) annotationProcessor("net.bytebuddy:$it:1.10.22") } // Required for Java 16 support } } tasks { withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) { with(kotlinOptions) { freeCompilerArgs = listOf("-Xjvm-default=all", "-Xlambdas=indy") jvmTarget = if (javaVer.toInt() < 10) "1.$javaVer" else javaVer languageVersion = "1.5" apiVersion = rootProject.property("kotlin_stdlib_version").toString() } } withType(JavaCompile::class) { with(options) { encoding = "UTF-8" isFork = true // The following lines are required for Jabel: forkOptions.jvmArgs!!.addAll(listOf( "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", "--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" )) // Java 16+ support compilerArgs.addAll(listOf("-Xplugin:jabel", "--release", javaVer)) } } withType(ProcessResources::class) { with(project(":common").sourceSets.main.get().resources.srcDirs) { if (!sourceSets.main.get().resources.srcDirs.containsAll(this)) { from(this) } } val modProperties = mapOf( "mod_version" to (rootProject.version as String), "minecraft_version" to mcBase, "java_version" to javaVer, "mod_group" to this@allprojects.group, "fabric_kotlin" to rootProject.property("fabric_language_kotlin"), "kotlinforforge" to rootProject.property("kotlinforforge") ) inputs.properties(modProperties) filesNotMatching(listOf("*.png")) { expand(modProperties) } } check { setDependsOn( dependsOn.minus(test) ) } } } tasks { file("remappedJars").let { if (it.exists()) clean.get().delete.add(it) } val publishToModrinth = register("publishtoModrinth") { val envStr: String? = System.getenv("MODRINTH") onlyIf { envStr != null } versionNumber = version.toString() projectId = "OuGyGg6A" token = envStr addGameVersion(mcBase) addDependency("jHsApOJC", com.modrinth.minotaur.request.Dependency.DependencyType.REQUIRED) // Kotlinforforge dependency versionType = VersionType.ALPHA detectLoaders = false versionName = "${project.name} $versionNumber for Minecraft $gameVersions and higher" fileTree("$rootDir/remappedJars/").files.forEach { with(it.name) { when { contains("fabric") -> uploadFile = it contains("forge") -> addFile(it) } } } addLoader("fabric"); addLoader("forge") } build.get().finalizedBy(publishToModrinth) }