Skip to content

Commit

Permalink
Release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Aug 2, 2024
1 parent 33263d7 commit 0c5b3bb
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions changes/1.1.1.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin<Project> {
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)
Expand Down Expand Up @@ -126,7 +117,7 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin<Project> {
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")
Expand All @@ -140,20 +131,32 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin<Project> {
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"
Expand Down Expand Up @@ -299,17 +302,17 @@ class KordExPlugin @Inject constructor(problems: Problems) : Plugin<Project> {
}
}

if (extension.hasBot) {
if (extension.hasBot && extension.bot.mainClass.isPresent) {
target.tasks.withType<Jar> {
manifest {
attributes(
"Main-Class" to extension._bot.mainClass.get()
"Main-Class" to extension.bot.mainClass.get()
)
}
}

target.extensions.configure<JavaApplication> {
mainClass = extension._bot.mainClass
mainClass = extension.bot.mainClass
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,47 @@
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<Boolean>
abstract val configurations: ListProperty<String>
abstract val ignoreIncompatibleKotlinVersion: Property<Boolean>

abstract val kordExVersion: Property<String>
abstract val kordVersion: Property<String>

abstract val modules: ListProperty<String>

@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<KordExBotSettings>) {
action.execute(bot)

hasBot = true
}

fun plugin(action: Action<KordExPluginSettings>) {
action.execute(plugin)

hasPlugin = true
}

fun module(module: String) {
modules.add(module)
}

internal fun setup() {
_bot = (this as ExtensionAware).extensions.create<KordExBotSettings>("bot")
_plugin = (this as ExtensionAware).extensions.create<KordExPluginSettings>("plugin")

_bot.setup()

addRepositories.convention(true)
ignoreIncompatibleKotlinVersion.convention(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
val dataCollection: Property<DataCollection>
val voice: Property<Boolean>
class KordExBotSettings(props: PropertyFactory) {
val mainClass: Property<String> = props.property(String::class.java)
val dataCollection: Property<DataCollection> = props.property(DataCollection::class.java)
val voice: Property<Boolean> = props.property(Boolean::class.javaObjectType).convention(true)

fun dataCollection(level: DataCollection?) {
dataCollection.set(level ?: DataCollection.None)
}
}

internal fun KordExBotSettings.setup() {
voice.convention(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
val id: Property<String>
val version: Property<String>
class KordExPluginSettings(props: PropertyFactory) {
val pluginClass: Property<String> = props.property(String::class.java)
val id: Property<String> = props.property(String::class.java)
val version: Property<String> = props.property(String::class.java)

val author: Property<String>
val description: Property<String>
val license: Property<String>
val author: Property<String> = props.property(String::class.java)
val description: Property<String> = props.property(String::class.java)
val license: Property<String> = props.property(String::class.java)

val kordExVersionSpecifier: Property<String>
val dependencies: ListProperty<String>
val kordExVersionSpecifier: Property<String> = props.property(String::class.java)
val dependencies: ListProperty<String> = 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.
Expand Down
7 changes: 3 additions & 4 deletions testModule/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -11,8 +12,6 @@ repositories {
}

kordEx {
ignoreIncompatibleKotlinVersion = true

bot {
mainClass = "template.MainKt"
}
Expand Down

0 comments on commit 0c5b3bb

Please sign in to comment.