diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index a317e5a6..e645eb2b 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -1,5 +1,6 @@ plugins { `kotlin-dsl` + id("org.jlleitschuh.gradle.ktlint") } repositories { @@ -12,4 +13,7 @@ dependencies { implementation(libs.gradleTestLogger) implementation(libs.gradleErrorprone) implementation(libs.licenser) + implementation(libs.gradleKotlinJvm) + implementation(libs.gradleDokka) + implementation(libs.gradleKtlint) } diff --git a/build-logic/src/main/kotlin/cloud.base-conventions.gradle.kts b/build-logic/src/main/kotlin/cloud.base-conventions.gradle.kts index 98e456ca..fc0baf2e 100644 --- a/build-logic/src/main/kotlin/cloud.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/cloud.base-conventions.gradle.kts @@ -27,13 +27,13 @@ tasks { options.errorprone { /* These are just annoying */ disable( - "JdkObsolete", - "FutureReturnValueIgnored", - "ImmutableEnumChecker", - "StringSplitter", - "EqualsGetClass", - "CatchAndPrintStackTrace", - "InlineMeSuggester", + "JdkObsolete", + "FutureReturnValueIgnored", + "ImmutableEnumChecker", + "StringSplitter", + "EqualsGetClass", + "CatchAndPrintStackTrace", + "InlineMeSuggester", ) } options.compilerArgs.addAll(listOf("-Xlint:-processing", "-Werror")) diff --git a/build-logic/src/main/kotlin/cloud.kotlin-conventions.gradle.kts b/build-logic/src/main/kotlin/cloud.kotlin-conventions.gradle.kts new file mode 100644 index 00000000..cb504a81 --- /dev/null +++ b/build-logic/src/main/kotlin/cloud.kotlin-conventions.gradle.kts @@ -0,0 +1,52 @@ +import org.jetbrains.dokka.gradle.DokkaTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("cloud.base-conventions") + kotlin("jvm") + id("org.jetbrains.dokka") + id("org.jlleitschuh.gradle.ktlint") +} + +kotlin { + jvmToolchain { + (this as JavaToolchainSpec).apply { + languageVersion.set(JavaLanguageVersion.of(8)) + } + } +} + +val compileAndTest: Configuration by configurations.creating +listOf(configurations.compileOnly, configurations.testImplementation).forEach { config -> + config { + extendsFrom(compileAndTest) + } +} + +dependencies { + compileAndTest(kotlin("stdlib-jdk8")) +} + +tasks { + withType { + dokkaSourceSets.named("main") { + includes.from(layout.projectDirectory.file("src/main/descriptions.md")) + /*externalDocumentationLink { // todo: fix KDoc linking to JavaDoc + url.set(URL("https://javadoc.commandframework.cloud/")) + packageListUrl.set(URL("https://javadoc.commandframework.cloud/allpackages-index.html")) + }*/ + } + } + javadocJar { + from(dokkaHtml) + } + withType { + kotlinOptions { + jvmTarget = "1.8" + } + } +} + +kotlin { + explicitApi() +} diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index b0cfb612..8b48967d 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -4,11 +4,11 @@ import org.gradle.api.provider.Provider // set by GitHub Actions val Project.ci: Provider get() = providers.environmentVariable("CI") - .forUseAtConfigurationTime() - .map { it.toBoolean() } - .orElse(false) + .forUseAtConfigurationTime() + .map { it.toBoolean() } + .orElse(false) val Project.compileExamples: Boolean get() = providers.gradleProperty("compile-examples") - .forUseAtConfigurationTime() - .isPresent + .forUseAtConfigurationTime() + .isPresent diff --git a/cloud-kotlin-extensions/build.gradle.kts b/cloud-kotlin-extensions/build.gradle.kts deleted file mode 100644 index 51996a53..00000000 --- a/cloud-kotlin-extensions/build.gradle.kts +++ /dev/null @@ -1,59 +0,0 @@ -import org.jetbrains.dokka.gradle.DokkaTask - -plugins { - kotlin("jvm") version "1.5.30" - id("org.jetbrains.dokka") version "1.5.30" - id("org.jlleitschuh.gradle.ktlint") version "10.0.0" -} - -val compileAndTest: Configuration by configurations.creating - -configurations { - all { - dependencies.removeIf { it.group == "org.jetbrains.kotlin" } - } - - compileOnly { - extendsFrom(compileAndTest) - } - testImplementation { - extendsFrom(compileAndTest) - } -} - -dependencies { - api(project(":cloud-core")) - - compileAndTest(project(":cloud-annotations")) - compileAndTest(kotlin("stdlib-jdk8")) - compileAndTest(kotlin("reflect")) - compileAndTest("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") - compileAndTest("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.2") -} - -tasks { - withType().configureEach { - dokkaSourceSets.getByName("main") { - includes.from(layout.projectDirectory.file("src/main/descriptions.md").toString()) - /* - externalDocumentationLink { - url.set(URL("https://javadoc.commandframework.cloud/")) //todo fix KDoc linking to JavaDoc - packageListUrl.set(URL("https://javadoc.commandframework.cloud/allpackages-index.html")) - } - */ - } - } - javadocJar { - from(dokkaHtml) - } - compileKotlin { - kotlinOptions.jvmTarget = "1.8" - } - compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" - } -} - -kotlin { - explicitApi() -} diff --git a/cloud-kotlin/cloud-kotlin-coroutines-annotations/build.gradle.kts b/cloud-kotlin/cloud-kotlin-coroutines-annotations/build.gradle.kts new file mode 100644 index 00000000..09eb3586 --- /dev/null +++ b/cloud-kotlin/cloud-kotlin-coroutines-annotations/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("cloud.kotlin-conventions") +} + +dependencies { + api(project(":cloud-core")) + api(project(":cloud-annotations")) + api(kotlin("reflect")) + api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") + api("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.2") +} diff --git a/cloud-kotlin/cloud-kotlin-coroutines-annotations/src/main/descriptions.md b/cloud-kotlin/cloud-kotlin-coroutines-annotations/src/main/descriptions.md new file mode 100644 index 00000000..4c6147f6 --- /dev/null +++ b/cloud-kotlin/cloud-kotlin-coroutines-annotations/src/main/descriptions.md @@ -0,0 +1,7 @@ +# Module cloud-kotlin-coroutines-annotations + +cloud-annotations extensions for Kotlin coroutine integration. + +# Package cloud.commandframework.kotlin.coroutines.annotations + +cloud-kotlin-coroutines-annotations classes and functions. diff --git a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethods.kt b/cloud-kotlin/cloud-kotlin-coroutines-annotations/src/main/kotlin/cloud/commandframework/kotlin/coroutines/annotations/KotlinAnnotatedMethods.kt similarity index 95% rename from cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethods.kt rename to cloud-kotlin/cloud-kotlin-coroutines-annotations/src/main/kotlin/cloud/commandframework/kotlin/coroutines/annotations/KotlinAnnotatedMethods.kt index 34ea6704..0ef3524b 100644 --- a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethods.kt +++ b/cloud-kotlin/cloud-kotlin-coroutines-annotations/src/main/kotlin/cloud/commandframework/kotlin/coroutines/annotations/KotlinAnnotatedMethods.kt @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package cloud.commandframework.kotlin.coroutines +package cloud.commandframework.kotlin.coroutines.annotations import cloud.commandframework.annotations.AnnotationParser import cloud.commandframework.annotations.MethodCommandExecutionHandler @@ -43,12 +43,15 @@ import kotlin.reflect.jvm.kotlinFunction /** * Adds coroutine support to the [AnnotationParser]. * + * @param scope coroutine scope + * @param context coroutine context + * @return annotation parser * @since 1.6.0 */ public fun AnnotationParser.installCoroutineSupport( scope: CoroutineScope = GlobalScope, context: CoroutineContext = EmptyCoroutineContext -) { +): AnnotationParser { if (manager().commandExecutionCoordinator() is CommandExecutionCoordinator.SimpleCoordinator) { RuntimeException( """You are highly advised to not use the simple command execution coordinator together @@ -61,6 +64,8 @@ public fun AnnotationParser.installCoroutineSupport( registerCommandExecutionMethodFactory(predicate) { KotlinMethodCommandExecutionHandler(scope, context, it) } + + return this } private class KotlinMethodCommandExecutionHandler( diff --git a/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethodsTest.kt b/cloud-kotlin/cloud-kotlin-coroutines-annotations/src/test/kotlin/cloud/commandframework/kotlin/coroutines/annotations/KotlinAnnotatedMethodsTest.kt similarity index 96% rename from cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethodsTest.kt rename to cloud-kotlin/cloud-kotlin-coroutines-annotations/src/test/kotlin/cloud/commandframework/kotlin/coroutines/annotations/KotlinAnnotatedMethodsTest.kt index 0881d4ea..c1cb7dc0 100644 --- a/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethodsTest.kt +++ b/cloud-kotlin/cloud-kotlin-coroutines-annotations/src/test/kotlin/cloud/commandframework/kotlin/coroutines/annotations/KotlinAnnotatedMethodsTest.kt @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package cloud.commandframework.kotlin.coroutines +package cloud.commandframework.kotlin.coroutines.annotations import cloud.commandframework.CommandManager import cloud.commandframework.annotations.AnnotationParser @@ -65,7 +65,7 @@ class KotlinAnnotatedMethodsTest { AnnotationParser(commandManager, TestCommandSender::class.java) { SimpleCommandMeta.empty() } - .also { it.installCoroutineSupport() } + .installCoroutineSupport() .parse(CommandMethods()) commandManager.executeCommand(TestCommandSender(), "test").await() @@ -76,7 +76,7 @@ class KotlinAnnotatedMethodsTest { AnnotationParser(commandManager, TestCommandSender::class.java) { SimpleCommandMeta.empty() } - .also { it.installCoroutineSupport() } + .installCoroutineSupport() .parse(CommandMethods()) assertThrows { diff --git a/cloud-kotlin/cloud-kotlin-extensions/build.gradle.kts b/cloud-kotlin/cloud-kotlin-extensions/build.gradle.kts new file mode 100644 index 00000000..07c0a675 --- /dev/null +++ b/cloud-kotlin/cloud-kotlin-extensions/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + id("cloud.kotlin-conventions") +} + +dependencies { + api(project(":cloud-core")) +} diff --git a/cloud-kotlin-extensions/src/main/descriptions.md b/cloud-kotlin/cloud-kotlin-extensions/src/main/descriptions.md similarity index 100% rename from cloud-kotlin-extensions/src/main/descriptions.md rename to cloud-kotlin/cloud-kotlin-extensions/src/main/descriptions.md diff --git a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt b/cloud-kotlin/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt similarity index 100% rename from cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt rename to cloud-kotlin/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt diff --git a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt b/cloud-kotlin/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt similarity index 100% rename from cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt rename to cloud-kotlin/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt diff --git a/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt b/cloud-kotlin/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt similarity index 100% rename from cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt rename to cloud-kotlin/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt diff --git a/gradle.properties b/gradle.properties index 28863b7d..dc1e806b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ org.gradle.caching=true org.gradle.parallel=true org.gradle.jvmargs=-Xmx1G + +kotlin.stdlib.default.dependency=false diff --git a/gradle/libs.versions.yml b/gradle/libs.versions.yml index ee4bdc5f..4759eee6 100644 --- a/gradle/libs.versions.yml +++ b/gradle/libs.versions.yml @@ -6,8 +6,11 @@ metadata: plugins: com.github.johnrengelman.shadow: 7.1.0 com.github.ben-manes.versions: 0.36.0 + org.jlleitschuh.gradle.ktlint: &ktlint 10.2.0 versions: + kotlin: &kotlin 1.5.31 + dokka: *kotlin checkerQual: 3.14.0 # build-logic @@ -15,6 +18,7 @@ versions: gradleTestLogger: 3.0.0 gradleErrorprone: 2.0.2 licenser: 0.6.1 + ktlint: *ktlint dependencies: checkerQual: @@ -43,5 +47,17 @@ dependencies: group: net.ltgt.gradle name: gradle-errorprone-plugin version: { ref: gradleErrorprone } + gradleKotlinJvm: + group: org.jetbrains.kotlin.jvm + name: org.jetbrains.kotlin.jvm.gradle.plugin + version: { ref: kotlin } + gradleDokka: + group: org.jetbrains.dokka + name: dokka-gradle-plugin + version: { ref: dokka } + gradleKtlint: + group: org.jlleitschuh.gradle + name: ktlint-gradle + version: { ref: ktlint } bundles: diff --git a/settings.gradle.kts b/settings.gradle.kts index 2dfa0203..b6bc677c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,8 +22,9 @@ include(":cloud-services") include(":cloud-tasks") include(":cloud-annotations") -// Extension Modules -include(":cloud-kotlin-extensions") +// Kotlin Extensions +setupKotlinModule("cloud-kotlin-extensions") +setupKotlinModule("cloud-kotlin-coroutines-annotations") // Discord Modules setupDiscordModule("cloud-javacord") @@ -59,6 +60,9 @@ fun setupDiscordModule(name: String) = fun setupMinecraftModule(name: String) = setupSubproject(name, file("cloud-minecraft/$name")) +fun setupKotlinModule(name: String) = + setupSubproject(name, file("cloud-kotlin/$name")) + fun setupExampleModule(name: String) = setupSubproject(name, file("examples/$name"))