diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index 46cd6da..fe63bb6 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/changes/1.1.1.md b/changes/1.1.1.md
new file mode 100644
index 0000000..153bdc9
--- /dev/null
+++ b/changes/1.1.1.md
@@ -0,0 +1,13 @@
+# Gradle Plugins 1.1.1
+
+This version targets the KordEx plugin.
+
+## KordEx Plugin
+
+This release includes the following changes:
+
+- Automatically adds the KordEx annotation processor when you apply the KSP plugin to the project.
+- Fix a typo that prevented the Fabric repo from being added to your project's repositories when using the `extra-mappings` module.
+- Support for optionally supplying custom configurations to apply dependencies to.
+- Support for projects that aren't bots or plugins, such as standalone modules. This means you can go back to omitting the `kordEx { }` block, or omit the `bot { }` and `plugin { }` blocks, and the plugin will work as expected.
+- Non-bot or -plugin projects will automatically avoid depending on Kord's voice module.
diff --git a/gradle.properties b/gradle.properties
index 6d8bd5c..b883950 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,4 +4,4 @@ org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m
org.gradle.parallel=true
kordExKotlinVersion=2.0.20-Beta1
-projectVersion=1.1.0
+projectVersion=1.1.1
diff --git a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/KordExPlugin.kt b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/KordExPlugin.kt
index 8d6187f..2175c09 100644
--- a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/KordExPlugin.kt
+++ b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/KordExPlugin.kt
@@ -54,15 +54,6 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin {
solution("If you need both in the same project, split them into separate Gradle subprojects")
severity(Severity.ERROR)
}
- } else if (!extension.hasBot && !extension.hasPlugin) {
- problemReporter.reporting {
- id("no-bot-or-plugin", "Project '${target.name} is neither bot nor plugin")
- details("Project ${target.name} doesn't have a bot or plugin configured, so there's nothing to do")
- solution("Configure a bot or plugin via the 'bot or 'plugin' builders in the 'kordEx' builder")
- severity(Severity.WARNING)
- }
-
- return@afterEvaluate
}
val versions = calculateVersions(extension)
@@ -126,7 +117,7 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin {
val modules = extension.modules.get().normalizeModules()
if ("extra-mappings" in modules) {
- target.repo("https://maven.fabricmc.net`")
+ target.repo("https://maven.fabricmc.net")
target.repo("https://maven.quiltmc.org/repository/release")
target.repo("https://maven.quiltmc.org/repository/snapshot")
target.repo("https://maven.shedaniel.me")
@@ -140,20 +131,32 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin {
kordExVersion: Version,
kordVersion: Version?
) {
- val configurations = if (extension.hasPlugin) {
+ val configurations = if (extension.configurations.isPresent && extension.configurations.get().isNotEmpty()) {
+ extension.configurations.get().toTypedArray()
+ } else if (extension.hasPlugin) {
arrayOf("compileOnly")
} else {
arrayOf("implementation")
}
target.afterEvaluate {
+ target.pluginManager.withPlugin("com.google.devtools.ksp") {
+ logger.info("KSP plugin detected, adding Kord Extensions annotation processor")
+
+ target.addDependency(
+ arrayOf("ksp"),
+ "com.kotlindiscord.kord.extensions:annotation-processor:$kordExVersion"
+ )
+ }
+
target.addDependency(
configurations,
"com.kotlindiscord.kord.extensions:kord-extensions:$kordExVersion"
) { exclude("dev.kord", "kord-core-voice") }
if (kordVersion != null) {
- if (extension.hasPlugin || extension._bot.voice.get()) {
+ @Suppress("UnnecessaryParentheses") // Reads better
+ if (extension.hasPlugin || (extension.hasBot && extension.bot.voice.get())) {
target.addDependency(
configurations,
"dev.kord:kord-core-voice:$kordVersion"
@@ -299,17 +302,17 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin {
}
}
- if (extension.hasBot) {
+ if (extension.hasBot && extension.bot.mainClass.isPresent) {
target.tasks.withType {
manifest {
attributes(
- "Main-Class" to extension._bot.mainClass.get()
+ "Main-Class" to extension.bot.mainClass.get()
)
}
}
target.extensions.configure {
- mainClass = extension._bot.mainClass
+ mainClass = extension.bot.mainClass
}
}
}
diff --git a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/base/KordExExtension.kt b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/base/KordExExtension.kt
index 63e9115..4159a56 100644
--- a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/base/KordExExtension.kt
+++ b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/base/KordExExtension.kt
@@ -7,15 +7,17 @@
package dev.kordex.gradle.plugins.kordex.base
import dev.kordex.gradle.plugins.kordex.bot.KordExBotSettings
-import dev.kordex.gradle.plugins.kordex.bot.setup
import dev.kordex.gradle.plugins.kordex.plugins.KordExPluginSettings
+import org.gradle.api.Action
+import org.gradle.api.internal.provider.PropertyFactory
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
-import org.gradle.kotlin.dsl.create
+import javax.inject.Inject
-abstract class KordExExtension : ExtensionAware {
+abstract class KordExExtension @Inject constructor(props: PropertyFactory) : ExtensionAware {
abstract val addRepositories: Property
+ abstract val configurations: ListProperty
abstract val ignoreIncompatibleKotlinVersion: Property
abstract val kordExVersion: Property
@@ -23,25 +25,29 @@ abstract class KordExExtension : ExtensionAware {
abstract val modules: ListProperty
- @Suppress("VariableNaming", "PropertyName")
- internal lateinit var _bot: KordExBotSettings
+ internal val bot: KordExBotSettings = KordExBotSettings(props)
+ internal val plugin: KordExPluginSettings = KordExPluginSettings(props)
- @Suppress("VariableNaming", "PropertyName")
- internal lateinit var _plugin: KordExPluginSettings
+ internal var hasBot = false
+ internal var hasPlugin = false
- internal val hasBot: Boolean get() = _bot.mainClass.isPresent
- internal val hasPlugin: Boolean get() = _plugin.pluginClass.isPresent
+ fun bot(action: Action) {
+ action.execute(bot)
+
+ hasBot = true
+ }
+
+ fun plugin(action: Action) {
+ action.execute(plugin)
+
+ hasPlugin = true
+ }
fun module(module: String) {
modules.add(module)
}
internal fun setup() {
- _bot = (this as ExtensionAware).extensions.create("bot")
- _plugin = (this as ExtensionAware).extensions.create("plugin")
-
- _bot.setup()
-
addRepositories.convention(true)
ignoreIncompatibleKotlinVersion.convention(false)
}
diff --git a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotHelper.kt b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotHelper.kt
index 7049db7..7f92def 100644
--- a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotHelper.kt
+++ b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotHelper.kt
@@ -39,7 +39,7 @@ object KordExBotHelper {
properties.setProperty(
"settings.dataCollection",
- extension._bot.dataCollection.orNull?.readable.toString()
+ extension.bot.dataCollection.orNull?.readable.toString()
)
properties.setProperty("modules", extension.modules.get().joinToString())
diff --git a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotSettings.kt b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotSettings.kt
index 4d9708c..3607988 100644
--- a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotSettings.kt
+++ b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/bot/KordExBotSettings.kt
@@ -7,18 +7,15 @@
package dev.kordex.gradle.plugins.kordex.bot
import dev.kordex.gradle.plugins.kordex.DataCollection
+import org.gradle.api.internal.provider.PropertyFactory
import org.gradle.api.provider.Property
-interface KordExBotSettings {
- val mainClass: Property
- val dataCollection: Property
- val voice: Property
+class KordExBotSettings(props: PropertyFactory) {
+ val mainClass: Property = props.property(String::class.java)
+ val dataCollection: Property = props.property(DataCollection::class.java)
+ val voice: Property = props.property(Boolean::class.javaObjectType).convention(true)
fun dataCollection(level: DataCollection?) {
dataCollection.set(level ?: DataCollection.None)
}
}
-
-internal fun KordExBotSettings.setup() {
- voice.convention(true)
-}
diff --git a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginHelper.kt b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginHelper.kt
index a4be4cd..25f7110 100644
--- a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginHelper.kt
+++ b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginHelper.kt
@@ -80,9 +80,9 @@ object KordExPluginHelper {
}
val requiredProperties = mapOf(
- "plugin.pluginClass" to extension._plugin.pluginClass,
- "plugin.id" to extension._plugin.id,
- "plugin.version" to extension._plugin.version,
+ "plugin -> pluginClass" to extension.plugin.pluginClass,
+ "plugin -> id" to extension.plugin.id,
+ "plugin -> version" to extension.plugin.version,
)
requiredProperties.forEach { (key, value) ->
@@ -104,28 +104,28 @@ object KordExPluginHelper {
doLast {
val properties = Properties()
- properties.setProperty("plugin.class", extension._plugin.pluginClass.get())
- properties.setProperty("plugin.id", extension._plugin.id.get())
- properties.setProperty("plugin.version", extension._plugin.version.get())
+ properties.setProperty("plugin.class", extension.plugin.pluginClass.get())
+ properties.setProperty("plugin.id", extension.plugin.id.get())
+ properties.setProperty("plugin.version", extension.plugin.version.get())
- if (extension._plugin.author.isPresent) {
- properties.setProperty("plugin.provider", extension._plugin.author.get())
+ if (extension.plugin.author.isPresent) {
+ properties.setProperty("plugin.provider", extension.plugin.author.get())
}
- if (!extension._plugin.dependencies.orNull.isNullOrEmpty()) {
- properties.setProperty("plugin.dependencies", extension._plugin.dependencies.get().joinToString())
+ if (!extension.plugin.dependencies.orNull.isNullOrEmpty()) {
+ properties.setProperty("plugin.dependencies", extension.plugin.dependencies.get().joinToString())
}
- if (extension._plugin.description.isPresent) {
- properties.setProperty("plugin.description", extension._plugin.description.get())
+ if (extension.plugin.description.isPresent) {
+ properties.setProperty("plugin.description", extension.plugin.description.get())
}
- if (extension._plugin.license.isPresent) {
- properties.setProperty("plugin.license", extension._plugin.license.get())
+ if (extension.plugin.license.isPresent) {
+ properties.setProperty("plugin.license", extension.plugin.license.get())
}
- if (extension._plugin.kordExVersionSpecifier.isPresent) {
- properties.setProperty("plugin.requires", extension._plugin.kordExVersionSpecifier.get())
+ if (extension.plugin.kordExVersionSpecifier.isPresent) {
+ properties.setProperty("plugin.requires", extension.plugin.kordExVersionSpecifier.get())
}
properties.store(outputFile.get().asFile.writer(), null)
diff --git a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginSettings.kt b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginSettings.kt
index f67e2cb..bcb18bd 100644
--- a/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginSettings.kt
+++ b/kordex/src/main/kotlin/dev/kordex/gradle/plugins/kordex/plugins/KordExPluginSettings.kt
@@ -7,20 +7,21 @@
package dev.kordex.gradle.plugins.kordex.plugins
import com.github.zafarkhaja.semver.expr.ExpressionParser
+import org.gradle.api.internal.provider.PropertyFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
-interface KordExPluginSettings {
- val pluginClass: Property
- val id: Property
- val version: Property
+class KordExPluginSettings(props: PropertyFactory) {
+ val pluginClass: Property = props.property(String::class.java)
+ val id: Property = props.property(String::class.java)
+ val version: Property = props.property(String::class.java)
- val author: Property
- val description: Property
- val license: Property
+ val author: Property = props.property(String::class.java)
+ val description: Property = props.property(String::class.java)
+ val license: Property = props.property(String::class.java)
- val kordExVersionSpecifier: Property
- val dependencies: ListProperty
+ val kordExVersionSpecifier: Property = props.property(String::class.java)
+ val dependencies: ListProperty = props.listProperty(String::class.java)
fun dependency(id: String, versionSpecifier: String? = null, optional: Boolean = false) {
// Try to parse the expression as pf4j does, to check validity.
diff --git a/testModule/build.gradle.kts b/testModule/build.gradle.kts
index 5a85221..754818e 100644
--- a/testModule/build.gradle.kts
+++ b/testModule/build.gradle.kts
@@ -1,7 +1,8 @@
plugins {
- kotlin("jvm") version "2.0.20-Beta2"
+ kotlin("jvm") version "2.0.20-Beta1"
- id("dev.kordex.gradle.kordex") version "1.1.0"
+ id("dev.kordex.gradle.kordex") version "1.1.1"
+// id("com.google.devtools.ksp") version "2.0.20-Beta1-1.0.22"
}
version = "1.0.0"
@@ -11,8 +12,6 @@ repositories {
}
kordEx {
- ignoreIncompatibleKotlinVersion = true
-
bot {
mainClass = "template.MainKt"
}