SnowyGUI/build.gradle.kts

255 lines
11 KiB
Plaintext
Raw Normal View History

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")
}
}
}
2021-04-08 10:18:46 +02:00
plugins {
kotlin("jvm") version "1.5.20-M1"
kotlin("plugin.serialization") version "1.5.20-M1"
2021-05-26 19:53:09 +02:00
id("com.github.johnrengelman.shadow") version "7.0.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.39.0"
2021-05-17 15:39:54 +02:00
id("net.kyori.indra.git") version "2.0.4"
2021-05-08 17:56:05 +02:00
id("com.modrinth.minotaur") version "1.2.1"
2021-04-08 10:18:46 +02:00
}
group = "fr.username404"
version = "0.0.1"
val groupAndName = "${rootProject.group}.${rootProject.name.toLowerCase()}"
architectury {
minecraft = rootProject.property("minecraft") as String
}
val javaVer: String = "8"
val sourceJavaVer: String = "16"
val kotlinVer: String by rootProject
val kotlinBaseVer = kotlinVer.substring(0..2)
val serializationVer: String by rootProject
val mcBase: String = rootProject.architectury.minecraft.substring(0..3)
val kotlinX: String = "org.jetbrains.kotlinx"
2021-04-08 10:18:46 +02:00
subprojects {
group = rootProject.group.toString()
lateinit var mappingsDep: Dependency
2021-05-04 22:07:06 +02:00
apply(plugin = "dev.architectury.loom")
apply(plugin = "org.jetbrains.kotlin.plugin.serialization")
extensions.configure<net.fabricmc.loom.LoomGradleExtension>("loom") {
mappingsDep = officialMojangMappings()
silentMojangMappingsLicense()
mixinConfig("snowygui-mixins.json")
refmapName = "snowygui-common-refmap.json"
}
2021-04-08 10:18:46 +02:00
apply(plugin = "com.github.johnrengelman.shadow")
val shadowC by configurations.creating
repositories { maven(url = "https://jitpack.io"); mavenCentral() }
dependencies {
implementation("$kotlinX:kotlinx-coroutines-core:$kotlinBaseVer.0-RC")
implementation("$kotlinX:kotlinx-serialization-core:$serializationVer")
implementation("$kotlinX:kotlinx-serialization-json:$serializationVer")
listOf(
"$kotlinX:kotlinx-datetime:0.2.1",
"com.typesafe:config:1.4.1",
"io.github.config4k:config4k:0.4.2",
2021-05-27 20:00:35 +02:00
"org.jetbrains:annotations:20.1.0",
"com.github.Vatuu:discord-rpc:1.6.2"
).forEach { implementation(it); shadowC(it) { isTransitive = false; exclude("com.sun.jna") } }
"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)
}
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")
2021-05-27 20:00:35 +02:00
exclude("com/sun/jna/**/*") // The shadowed JNA from discord-rpc isn't needed since it is already available at runtime
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
2021-04-14 20:36:05 +02:00
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.**")
2021-04-27 20:40:12 +02:00
keepnames("class $group.snowygui.Snowy")
2021-05-20 17:46:28 +02:00
keepnames("class $group.snowygui.gui.feature.Macro { <fields>; }")
2021-05-18 22:14:35 +02:00
keep("class $group.snowygui.gui.feature.* { public static *** INSTANCE; }")
keepclassmembers("class $group.snowygui.** { public protected <methods>; }")
keepattributes("*Annotation*, Signature, InnerClasses, EnclosingMethod, MethodParameters, Synthetic, Exceptions")
2021-04-14 20:36:05 +02:00
obfuscationdictionary("$dictionariesDir/dictionary.txt")
classobfuscationdictionary("$dictionariesDir/classdictionary.txt")
packageobfuscationdictionary("$dictionariesDir/packagesdictionary.txt")
flattenpackagehierarchy("$group.snowygui")
2021-04-27 20:40:12 +02:00
allowaccessmodification()
adaptclassstrings()
2021-05-18 22:14:35 +02:00
"$group.**".also { dontnote(it); dontwarn(it) }
// kotlinx-serialization related configuration:
keep(mapOf("includedescriptorclasses" to true), "class $group.snowygui.**$\$serializer { * ; }")
keepclassmembers("class $group.snowygui.** { *** Companion; }")
keepclasseswithmembers("class $group.snowygui.** { kotlinx.serialization.KSerializer serializer(...); }")
2021-05-27 20:00:35 +02:00
// Required for discord-rpc
keepclassmembers("class $group.drpc.** { public * ; }")
2021-05-27 20:00:35 +02:00
doFirst {
libraryjars(configurations.compileClasspath.get().filterNot { file ->
shadowC.contains(file)
})
}
val homeDir = System.getProperty("java.home") as String
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)
archiveVersion.set("[${rootProject.version}+$mcBase]")
archiveClassifier.set(this@subprojects.name)
input.set(shrinkedJar)
if (!archiveFileName.get().contains("common")) destinationDirectory.set(file("$rootDir/remappedJars"))
}
2021-04-08 10:18:46 +02:00
}
}
allprojects {
/** configurations.all {
resolutionStrategy {
eachDependency {
if (requested.group == "org.jetbrains.kotlin" && requested.name.contains("stdlib") && (requested.version != kotlinVer)) {
useVersion(kotlinVer)
}
}
}
}
**/
2021-04-08 10:18:46 +02:00
apply(plugin = "java")
2021-05-18 22:14:35 +02:00
apply(plugin = "org.jetbrains.kotlin.jvm")
2021-04-08 10:18:46 +02:00
apply(plugin = "architectury-plugin")
val compiler = javaToolchains.compilerFor { languageVersion.set(JavaLanguageVersion.of(sourceJavaVer.toInt())) }
2021-04-20 15:03:40 +02:00
dependencies {
2021-05-03 14:34:49 +02:00
implementation(kotlin("stdlib-jdk8", kotlinVer))
implementation(kotlin("reflect", kotlinVer))
2021-05-15 13:44:21 +02:00
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
}
2021-04-20 15:03:40 +02:00
}
2021-04-08 10:18:46 +02:00
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
2021-04-08 10:18:46 +02:00
languageVersion = "1.5"
apiVersion = kotlinBaseVer
2021-04-08 10:18:46 +02:00
}
}
withType(JavaCompile::class) {
with(options) {
encoding = "UTF-8"
isFork = true
release.set(javaVer.toInt())
javaCompiler.set(compiler)
// The following lines are required for Jabel:
sourceCompatibility = sourceJavaVer
2021-05-15 13:44:21 +02:00
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"))
2021-04-08 10:18:46 +02:00
}
}
withType(ProcessResources::class) {
with(project(":common").sourceSets.main.get().resources.srcDirs) {
if (!sourceSets.main.get().resources.srcDirs.containsAll(this)) {
from(this)
}
}
2021-04-21 16:31:32 +02:00
val modProperties = mapOf(
"mod_version" to (rootProject.version as String),
"minecraft_version" to mcBase,
2021-05-12 17:10:14 +02:00
"java_version" to javaVer,
2021-05-07 10:33:35 +02:00
"mod_group" to this@allprojects.group,
"fabric_kotlin" to rootProject.property("fabric_language_kotlin"),
2021-05-29 22:11:05 +02:00
"kotlinforforge" to rootProject.property("kotlinforforge"),
"clothconfig" to rootProject.property("clothconfig_version")
)
2021-04-21 16:31:32 +02:00
inputs.properties(modProperties)
filesNotMatching(listOf("*.png")) {
2021-04-21 16:31:32 +02:00
expand(modProperties)
}
2021-04-08 10:18:46 +02:00
}
check {
setDependsOn(
dependsOn.minus(test)
)
}
2021-04-08 10:18:46 +02:00
}
}
tasks {
file("remappedJars").let { if (it.exists()) clean.get().delete.add(it) }
val publishToModrinth = register<com.modrinth.minotaur.TaskModrinthUpload>("publishtoModrinth") {
val envStr: String? = System.getenv("MODRINTH")
onlyIf { envStr != null }
versionNumber = version.toString()
projectId = "OuGyGg6A"
token = envStr
addGameVersion(mcBase)
addDependency("Bxm9xbNJ", 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)
}