diff --git a/buildSrc/src/main/kotlin/Compiler.kt b/buildSrc/src/main/kotlin/Compiler.kt index 00b3f31b5b6..6caa6484fc3 100644 --- a/buildSrc/src/main/kotlin/Compiler.kt +++ b/buildSrc/src/main/kotlin/Compiler.kt @@ -1,6 +1,8 @@ import org.gradle.api.NamedDomainObjectSet import org.gradle.kotlin.dsl.assign +import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet val kordOptIns = listOf( @@ -12,16 +14,20 @@ val kordOptIns = listOf( "dev.kord.common.annotation.KordVoice", ) -object Jvm { - const val target = 8 -} - -fun KotlinCommonCompilerOptions.applyKordCompilerOptions() { +internal fun KotlinCommonCompilerOptions.applyKordCommonCompilerOptions() { allWarningsAsErrors = true progressiveMode = true freeCompilerArgs.add("-Xexpect-actual-classes") } +internal const val KORD_JVM_TARGET = 8 + +internal fun KotlinJvmCompilerOptions.applyKordJvmCompilerOptions() { + applyKordCommonCompilerOptions() + jvmTarget = JVM_1_8 + freeCompilerArgs.add("-Xjdk-release=1.8") +} + internal fun NamedDomainObjectSet.applyKordTestOptIns() { named { it.contains("test", ignoreCase = true) }.configureEach { // allow `ExperimentalCoroutinesApi` for `TestScope.currentTime` diff --git a/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts index 102f730ea2e..ad9b04bb4d1 100644 --- a/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts @@ -7,8 +7,13 @@ repositories { } kotlin { - jvmToolchain(Jvm.target) compilerOptions { - applyKordCompilerOptions() + applyKordJvmCompilerOptions() + } +} + +tasks { + withType().configureEach { + options.release = KORD_JVM_TARGET } } diff --git a/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts index 236b1027f1c..076b387f80e 100644 --- a/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts @@ -8,18 +8,21 @@ repositories { mavenCentral() } +@OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { - jvm() + compilerOptions { + applyKordCommonCompilerOptions() + } + + jvm { + compilerOptions { + applyKordJvmCompilerOptions() + } + } js { nodejs() useCommonJs() } - jvmToolchain(Jvm.target) - - @OptIn(ExperimentalKotlinGradlePluginApi::class) - compilerOptions { - applyKordCompilerOptions() - } } tasks { diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index f46703c0f73..19322086bd4 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -24,11 +24,8 @@ apiValidation { kotlin { explicitApi() - - jvmToolchain(Jvm.target) - compilerOptions { - applyKordCompilerOptions() + applyKordJvmCompilerOptions() optIn.addAll(kordOptIns) } @@ -45,6 +42,10 @@ tasks { withType().configureEach { applyKordDokkaOptions() } + + withType().configureEach { + options.release = KORD_JVM_TARGET + } } publishing { diff --git a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts index 77ec746acbd..5a28f04dd8c 100644 --- a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts @@ -23,10 +23,19 @@ apiValidation { applyKordBCVOptions() } +@OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { explicitApi() + compilerOptions { + applyKordCommonCompilerOptions() + optIn.addAll(kordOptIns) + } - jvm() + jvm { + compilerOptions { + applyKordJvmCompilerOptions() + } + } js { nodejs { testTask { @@ -39,13 +48,6 @@ kotlin { } useCommonJs() } - jvmToolchain(Jvm.target) - - @OptIn(ExperimentalKotlinGradlePluginApi::class) - compilerOptions { - applyKordCompilerOptions() - optIn.addAll(kordOptIns) - } applyDefaultHierarchyTemplate() diff --git a/rest/api/rest.api b/rest/api/rest.api index e0a1f2426c5..dbf98504714 100644 --- a/rest/api/rest.api +++ b/rest/api/rest.api @@ -247,7 +247,6 @@ public final class dev/kord/rest/builder/automoderation/KeywordAutoModerationRul public final class dev/kord/rest/builder/automoderation/KeywordAutoModerationRuleCreateBuilder : dev/kord/rest/builder/automoderation/AutoModerationRuleCreateBuilder, dev/kord/rest/builder/automoderation/KeywordAutoModerationRuleBuilder { public fun (Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;)V - public synthetic fun buildTriggerMetadata ()Ldev/kord/common/entity/optional/Optional; public fun getAllowedKeywords ()Ljava/util/List; public fun getKeywords ()Ljava/util/List; public fun getRegexPatterns ()Ljava/util/List; @@ -274,6 +273,7 @@ public abstract interface class dev/kord/rest/builder/automoderation/KeywordPres public abstract fun assignPresets (Ljava/util/List;)V public abstract fun getPresets ()Ljava/util/List; public abstract fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$KeywordPreset; + public abstract fun setPresets (Ljava/util/List;)V } public final class dev/kord/rest/builder/automoderation/KeywordPresetAutoModerationRuleBuilder$DefaultImpls { @@ -283,7 +283,6 @@ public final class dev/kord/rest/builder/automoderation/KeywordPresetAutoModerat public final class dev/kord/rest/builder/automoderation/KeywordPresetAutoModerationRuleCreateBuilder : dev/kord/rest/builder/automoderation/AutoModerationRuleCreateBuilder, dev/kord/rest/builder/automoderation/KeywordPresetAutoModerationRuleBuilder { public fun (Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;)V public fun assignPresets (Ljava/util/List;)V - public synthetic fun buildTriggerMetadata ()Ldev/kord/common/entity/optional/Optional; public fun getAllowedKeywords ()Ljava/util/List; public fun getPresets ()Ljava/util/List; public fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$KeywordPreset; @@ -317,7 +316,6 @@ public final class dev/kord/rest/builder/automoderation/MentionSpamAutoModeratio public final class dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleCreateBuilder : dev/kord/rest/builder/automoderation/AutoModerationRuleCreateBuilder, dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleBuilder { public fun (Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;)V - public synthetic fun buildTriggerMetadata ()Ldev/kord/common/entity/optional/Optional; public fun getMentionLimit ()Ljava/lang/Integer; public fun getMentionRaidProtectionEnabled ()Ljava/lang/Boolean; public fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$MentionSpam; diff --git a/rest/api/rest.klib.api b/rest/api/rest.klib.api index 7bc4c21b67d..b6486c7787c 100644 --- a/rest/api/rest.klib.api +++ b/rest/api/rest.klib.api @@ -464,11 +464,13 @@ sealed interface dev.kord.rest.builder.automoderation/KeywordAutoModerationRuleB } sealed interface dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder : dev.kord.rest.builder.automoderation/AllowedKeywordsAutoModerationRuleBuilder { // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder|null[0] - abstract val presets // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.presets|{}presets[0] - abstract fun (): kotlin.collections/MutableList? // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.presets.|(){}[0] open val triggerType // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.triggerType|{}triggerType[0] open fun (): dev.kord.common.entity/AutoModerationRuleTriggerType.KeywordPreset // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.triggerType.|(){}[0] + abstract var presets // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.presets|{}presets[0] + abstract fun (): kotlin.collections/MutableList? // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.presets.|(){}[0] + abstract fun (kotlin.collections/MutableList?) // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.presets.|(kotlin.collections.MutableList?){}[0] + abstract fun assignPresets(kotlin.collections/MutableList) // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleBuilder.assignPresets|assignPresets(kotlin.collections.MutableList){}[0] } @@ -769,8 +771,8 @@ final class dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRule final fun (): kotlin.collections/MutableList? // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.allowedKeywords.|(){}[0] final fun (kotlin.collections/MutableList?) // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.allowedKeywords.|(kotlin.collections.MutableList?){}[0] final var presets // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.presets|{}presets[0] - final fun (): kotlin.collections/MutableList // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.presets.|(){}[0] - final fun (kotlin.collections/MutableList) // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.presets.|(kotlin.collections.MutableList){}[0] + final fun (): kotlin.collections/MutableList? // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.presets.|(){}[0] + final fun (kotlin.collections/MutableList?) // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.presets.|(kotlin.collections.MutableList?){}[0] final fun assignPresets(kotlin.collections/MutableList) // dev.kord.rest.builder.automoderation/KeywordPresetAutoModerationRuleCreateBuilder.assignPresets|assignPresets(kotlin.collections.MutableList){}[0] } diff --git a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt index b9bd19072b9..8b91fd43bce 100644 --- a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt @@ -282,18 +282,24 @@ public sealed interface KeywordPresetAutoModerationRuleBuilder : AllowedKeywords override val triggerType: KeywordPreset get() = KeywordPreset /** The internally pre-defined wordsets which will be searched for in content. */ - public val presets: MutableList? + public var presets: MutableList? /** * Use this to set [presets][KeywordPresetAutoModerationRuleBuilder.presets] for * [KeywordPresetAutoModerationRuleBuilder]. */ + @Deprecated( + "This can be replaced with 'presets', it is now a 'var'. The deprecation level will be raised to ERROR in " + + "0.16.0, to HIDDEN in 0.17.0, and this declaration will be removed in 0.18.0.", + ReplaceWith("this.run { this@run.presets = presets }", imports = ["kotlin.run"]), + DeprecationLevel.WARNING, + ) public fun assignPresets(presets: MutableList) } /** Add a [preset] to [presets][KeywordPresetAutoModerationRuleBuilder.presets]. */ public fun KeywordPresetAutoModerationRuleBuilder.preset(preset: AutoModerationRuleKeywordPresetType) { - presets?.add(preset) ?: assignPresets(mutableListOf(preset)) + presets?.add(preset) ?: run { presets = mutableListOf(preset) } } diff --git a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt index 82acfabeb75..2a90eaee32f 100644 --- a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt @@ -74,8 +74,8 @@ public class KeywordAutoModerationRuleCreateBuilder( private var _allowedKeywords: Optional> = Optional.Missing() override var allowedKeywords: MutableList? by ::_allowedKeywords.delegate() - // one of keywords or regexPatterns is required, don't bother to send missing trigger metadata if both are missing - override fun buildTriggerMetadata(): Optional.Value = + // triggerMetadata is required for Keyword rules + override fun buildTriggerMetadata(): Optional = DiscordAutoModerationRuleTriggerMetadata( keywordFilter = _keywords.mapCopy(), regexPatterns = _regexPatterns.mapCopy(), @@ -97,9 +97,16 @@ public class KeywordPresetAutoModerationRuleCreateBuilder( eventType: AutoModerationRuleEventType, ) : AutoModerationRuleCreateBuilder(name, eventType), KeywordPresetAutoModerationRuleBuilder { - override var presets: MutableList = mutableListOf() + private var _presets: Optional> = Optional.Missing() + override var presets: MutableList? by ::_presets.delegate() /** @suppress Use `this.presets = presets` instead. */ + @Deprecated( + "Use 'this.presets = presets' instead. The deprecation level will be raised to ERROR in 0.16.0, to HIDDEN in " + + "0.17.0, and this declaration will be removed in 0.18.0.", + ReplaceWith("this.run { this@run.presets = presets }", imports = ["kotlin.run"]), + DeprecationLevel.WARNING, + ) override fun assignPresets(presets: MutableList) { this.presets = presets } @@ -107,9 +114,10 @@ public class KeywordPresetAutoModerationRuleCreateBuilder( private var _allowedKeywords: Optional> = Optional.Missing() override var allowedKeywords: MutableList? by ::_allowedKeywords.delegate() - override fun buildTriggerMetadata(): Optional.Value = + // triggerMetadata is required for KeywordPreset rules + override fun buildTriggerMetadata(): Optional = DiscordAutoModerationRuleTriggerMetadata( - presets = presets.toList().optional(), + presets = _presets.mapCopy(), allowList = _allowedKeywords.mapCopy(), ).optional() } @@ -127,9 +135,8 @@ public class MentionSpamAutoModerationRuleCreateBuilder( private var _mentionRaidProtectionEnabled: OptionalBoolean = OptionalBoolean.Missing override var mentionRaidProtectionEnabled: Boolean? by ::_mentionRaidProtectionEnabled.delegate() - // one of mentionTotalLimit or mentionRaidProtectionEnabled is required, don't bother to send missing trigger - // metadata if both are missing - override fun buildTriggerMetadata(): Optional.Value = + // triggerMetadata is required for MentionSpam rules + override fun buildTriggerMetadata(): Optional = DiscordAutoModerationRuleTriggerMetadata( mentionTotalLimit = _mentionLimit, mentionRaidProtectionEnabled = _mentionRaidProtectionEnabled, diff --git a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt index 0bbeb537c30..133595999e9 100644 --- a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt @@ -103,7 +103,7 @@ public class KeywordAutoModerationRuleModifyBuilder : } /** A [SpamAutoModerationRuleBuilder] for building [AutoModerationRuleModifyRequest]s. */ -@Suppress("CanSealedSubClassBeObject") // has state in super class +@Suppress("CanSealedSubClassBeObject") // superclass is mutable @KordDsl public class SpamAutoModerationRuleModifyBuilder : AutoModerationRuleModifyBuilder(), @@ -119,6 +119,12 @@ public class KeywordPresetAutoModerationRuleModifyBuilder : override var presets: MutableList? by ::_presets.delegate() /** @suppress Use `this.presets = presets` instead. */ + @Deprecated( + "Use 'this.presets = presets' instead. The deprecation level will be raised to ERROR in 0.16.0, to HIDDEN in " + + "0.17.0, and this declaration will be removed in 0.18.0.", + ReplaceWith("this.run { this@run.presets = presets }", imports = ["kotlin.run"]), + DeprecationLevel.WARNING, + ) override fun assignPresets(presets: MutableList) { this.presets = presets } diff --git a/settings.gradle.kts b/settings.gradle.kts index d0ab04959b0..2a6e06084e9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,8 +1,3 @@ -plugins { - // https://github.com/gradle/foojay-toolchains - id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" -} - rootProject.name = "kord" include(