From 2fc47b11396f5c3786b90023c07d9e60d487fa22 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sun, 29 Jan 2023 22:24:31 +0000 Subject: [PATCH] RFG Kotlin fixes, update kotlin to 1.8, drop jdk7 --- addon.gradle | 6 ----- build.gradle | 65 +++++++++++++++++++++++++++++++++++++++++---- dependencies.gradle | 13 +++++---- gradle.properties | 5 ++++ 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/addon.gradle b/addon.gradle index 17e2283..f70506f 100644 --- a/addon.gradle +++ b/addon.gradle @@ -1,7 +1 @@ apply plugin: 'org.jetbrains.kotlin.jvm' - -compileKotlin { - kotlinOptions { - jvmTarget = 1.8 - } -} diff --git a/build.gradle b/build.gradle index 18afe43..d6e86aa 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1675013090 +//version: 1675030924 /* DO NOT CHANGE THIS FILE! Also, you may replace this file at any time if there is an update available. @@ -55,9 +55,9 @@ plugins { id 'eclipse' id 'scala' id 'maven-publish' - id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false - id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false - id 'com.google.devtools.ksp' version '1.5.30-1.0.0' apply false + id 'org.jetbrains.kotlin.jvm' version '1.8.0' apply false + id 'org.jetbrains.kotlin.kapt' version '1.8.0' apply false + id 'com.google.devtools.ksp' version '1.8.0-1.0.9' apply false id 'org.ajoberstar.grgit' version '4.1.1' // 4.1.1 is the last jvm8 supporting version ,unused, available for addon.gradle id 'com.github.johnrengelman.shadow' version '7.1.2' apply false id 'com.palantir.git-version' version '0.13.0' apply false // 0.13.0 is the last jvm8 supporting version @@ -113,6 +113,7 @@ propertyDefaultIfUnset("modrinthRelations", "") propertyDefaultIfUnset("curseForgeProjectId", "") propertyDefaultIfUnset("curseForgeRelations", "") propertyDefaultIfUnset("minimizeShadowedDependencies", true) +propertyDefaultIfUnset("relocateShadowedDependencies", true) // Deprecated properties (kept for backwards compat) propertyDefaultIfUnset("gradleTokenModId", "") propertyDefaultIfUnset("gradleTokenModName", "") @@ -149,6 +150,30 @@ java { } } +pluginManager.withPlugin('org.jetbrains.kotlin.jvm') { + // If Kotlin is enabled in the project + kotlin { + jvmToolchain(8) + } + // Kotlin hacks our source sets, so we hack Kotlin's tasks + def disabledKotlinTaskList = [ + "kaptGenerateStubsMcLauncherKotlin", + "kaptGenerateStubsPatchedMcKotlin", + "kaptGenerateStubsInjectedTagsKotlin", + "compileMcLauncherKotlin", + "compilePatchedMcKotlin", + "compileInjectedTagsKotlin", + "kaptMcLauncherKotlin", + "kaptPatchedMcKotlin", + "kaptInjectedTagsKotlin", + ] + tasks.configureEach { task -> + if (task.name in disabledKotlinTaskList) { + task.enabled = false + } + } +} + configurations { create("runtimeOnlyNonPublishable") { description = "Runtime only dependencies that are not published alongside the jar" @@ -502,6 +527,14 @@ dependencies { } } +pluginManager.withPlugin('org.jetbrains.kotlin.kapt') { + if (usesMixins.toBoolean()) { + dependencies { + kapt('com.gtnewhorizon:gtnhmixins:2.1.10:processor') + } + } +} + apply from: 'dependencies.gradle' def mixingConfigRefMap = 'mixins.' + modId + '.refmap.json' @@ -558,6 +591,25 @@ if (usesMixins.toBoolean()) { "-XDignore.symbol.file" ] } + + pluginManager.withPlugin('org.jetbrains.kotlin.kapt') { + kapt { + correctErrorTypes = true + javacOptions { + option("-AreobfSrgFile=${tasks.reobfJar.srg.get().asFile}") + option("-AoutSrgFile=$mixinSrg") + option("-AoutRefMapFile=$refMap") + } + } + tasks.configureEach { task -> + if (task.name == "kaptKotlin") { + task.doFirst { + new File(mixinTmpDir).mkdirs() + } + } + } + } + } tasks.named("processResources", ProcessResources).configure { @@ -613,6 +665,7 @@ if (usesShadowedDependencies.toBoolean()) { tasks.register('relocateShadowJar', ConfigureShadowRelocation) { target = tasks.shadowJar prefix = modGroup + ".shadow" + enabled = minimizeShadowedDependencies.toBoolean() } tasks.named("shadowJar", ShadowJar).configure { manifest { @@ -628,7 +681,9 @@ if (usesShadowedDependencies.toBoolean()) { project.configurations.shadeCompile ] archiveClassifier.set('dev') - dependsOn(relocateShadowJar) + if (minimizeShadowedDependencies.toBoolean()) { + dependsOn(relocateShadowJar) + } } configurations.runtimeElements.outgoing.artifacts.clear() configurations.apiElements.outgoing.artifacts.clear() diff --git a/dependencies.gradle b/dependencies.gradle index 097f51f..2ea6ca5 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,11 +1,10 @@ // Add your dependencies here dependencies { - shadeCompile("org.jetbrains.kotlin:kotlin-stdlib:1.5.30") - shadeCompile("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.30") - shadeCompile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30") - shadeCompile("org.jetbrains.kotlin:kotlin-reflect:1.5.30") - shadeCompile("org.jetbrains:annotations") - shadeCompile("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") - shadeCompile("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.2") + shadowImplementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.0") + shadowImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") + shadowImplementation("org.jetbrains.kotlin:kotlin-reflect:1.8.0") + shadowImplementation("org.jetbrains:annotations") + shadowImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") + shadowImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4") } diff --git a/gradle.properties b/gradle.properties index 6685c4f..69b5c28 100644 --- a/gradle.properties +++ b/gradle.properties @@ -67,6 +67,11 @@ containsMixinsAndOrCoreModOnly = false # If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your # responsibility check the licence and request permission for distribution, if required. usesShadowedDependencies = true +# If disabled, won't remove unused classes from shaded dependencies. Some libraries use reflection to access +# their own classes, making the minimization unreliable. +minimizeShadowedDependencies = false +# If disabled, won't rename the shadowed classes. +relocateShadowedDependencies = false # Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older # projects. New projects should not use this parameter.