Split kotlin modules (#316)

This commit is contained in:
Jason 2021-11-15 14:51:52 -08:00
parent 762de3dfba
commit d2a47ad941
17 changed files with 127 additions and 78 deletions

View file

@ -1,5 +1,6 @@
plugins { plugins {
`kotlin-dsl` `kotlin-dsl`
id("org.jlleitschuh.gradle.ktlint")
} }
repositories { repositories {
@ -12,4 +13,7 @@ dependencies {
implementation(libs.gradleTestLogger) implementation(libs.gradleTestLogger)
implementation(libs.gradleErrorprone) implementation(libs.gradleErrorprone)
implementation(libs.licenser) implementation(libs.licenser)
implementation(libs.gradleKotlinJvm)
implementation(libs.gradleDokka)
implementation(libs.gradleKtlint)
} }

View file

@ -27,13 +27,13 @@ tasks {
options.errorprone { options.errorprone {
/* These are just annoying */ /* These are just annoying */
disable( disable(
"JdkObsolete", "JdkObsolete",
"FutureReturnValueIgnored", "FutureReturnValueIgnored",
"ImmutableEnumChecker", "ImmutableEnumChecker",
"StringSplitter", "StringSplitter",
"EqualsGetClass", "EqualsGetClass",
"CatchAndPrintStackTrace", "CatchAndPrintStackTrace",
"InlineMeSuggester", "InlineMeSuggester",
) )
} }
options.compilerArgs.addAll(listOf("-Xlint:-processing", "-Werror")) options.compilerArgs.addAll(listOf("-Xlint:-processing", "-Werror"))

View file

@ -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<DokkaTask> {
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<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
kotlin {
explicitApi()
}

View file

@ -4,11 +4,11 @@ import org.gradle.api.provider.Provider
// set by GitHub Actions // set by GitHub Actions
val Project.ci: Provider<Boolean> val Project.ci: Provider<Boolean>
get() = providers.environmentVariable("CI") get() = providers.environmentVariable("CI")
.forUseAtConfigurationTime() .forUseAtConfigurationTime()
.map { it.toBoolean() } .map { it.toBoolean() }
.orElse(false) .orElse(false)
val Project.compileExamples: Boolean val Project.compileExamples: Boolean
get() = providers.gradleProperty("compile-examples") get() = providers.gradleProperty("compile-examples")
.forUseAtConfigurationTime() .forUseAtConfigurationTime()
.isPresent .isPresent

View file

@ -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<DokkaTask>().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()
}

View file

@ -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")
}

View file

@ -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.

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
package cloud.commandframework.kotlin.coroutines package cloud.commandframework.kotlin.coroutines.annotations
import cloud.commandframework.annotations.AnnotationParser import cloud.commandframework.annotations.AnnotationParser
import cloud.commandframework.annotations.MethodCommandExecutionHandler import cloud.commandframework.annotations.MethodCommandExecutionHandler
@ -43,12 +43,15 @@ import kotlin.reflect.jvm.kotlinFunction
/** /**
* Adds coroutine support to the [AnnotationParser]. * Adds coroutine support to the [AnnotationParser].
* *
* @param scope coroutine scope
* @param context coroutine context
* @return annotation parser
* @since 1.6.0 * @since 1.6.0
*/ */
public fun <C> AnnotationParser<C>.installCoroutineSupport( public fun <C> AnnotationParser<C>.installCoroutineSupport(
scope: CoroutineScope = GlobalScope, scope: CoroutineScope = GlobalScope,
context: CoroutineContext = EmptyCoroutineContext context: CoroutineContext = EmptyCoroutineContext
) { ): AnnotationParser<C> {
if (manager().commandExecutionCoordinator() is CommandExecutionCoordinator.SimpleCoordinator) { if (manager().commandExecutionCoordinator() is CommandExecutionCoordinator.SimpleCoordinator) {
RuntimeException( RuntimeException(
"""You are highly advised to not use the simple command execution coordinator together """You are highly advised to not use the simple command execution coordinator together
@ -61,6 +64,8 @@ public fun <C> AnnotationParser<C>.installCoroutineSupport(
registerCommandExecutionMethodFactory(predicate) { registerCommandExecutionMethodFactory(predicate) {
KotlinMethodCommandExecutionHandler(scope, context, it) KotlinMethodCommandExecutionHandler(scope, context, it)
} }
return this
} }
private class KotlinMethodCommandExecutionHandler<C>( private class KotlinMethodCommandExecutionHandler<C>(

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
package cloud.commandframework.kotlin.coroutines package cloud.commandframework.kotlin.coroutines.annotations
import cloud.commandframework.CommandManager import cloud.commandframework.CommandManager
import cloud.commandframework.annotations.AnnotationParser import cloud.commandframework.annotations.AnnotationParser
@ -65,7 +65,7 @@ class KotlinAnnotatedMethodsTest {
AnnotationParser(commandManager, TestCommandSender::class.java) { AnnotationParser(commandManager, TestCommandSender::class.java) {
SimpleCommandMeta.empty() SimpleCommandMeta.empty()
} }
.also { it.installCoroutineSupport() } .installCoroutineSupport()
.parse(CommandMethods()) .parse(CommandMethods())
commandManager.executeCommand(TestCommandSender(), "test").await() commandManager.executeCommand(TestCommandSender(), "test").await()
@ -76,7 +76,7 @@ class KotlinAnnotatedMethodsTest {
AnnotationParser(commandManager, TestCommandSender::class.java) { AnnotationParser(commandManager, TestCommandSender::class.java) {
SimpleCommandMeta.empty() SimpleCommandMeta.empty()
} }
.also { it.installCoroutineSupport() } .installCoroutineSupport()
.parse(CommandMethods()) .parse(CommandMethods())
assertThrows<CommandExecutionException> { assertThrows<CommandExecutionException> {

View file

@ -0,0 +1,7 @@
plugins {
id("cloud.kotlin-conventions")
}
dependencies {
api(project(":cloud-core"))
}

View file

@ -1,3 +1,5 @@
org.gradle.caching=true org.gradle.caching=true
org.gradle.parallel=true org.gradle.parallel=true
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
kotlin.stdlib.default.dependency=false

View file

@ -6,8 +6,11 @@ metadata:
plugins: plugins:
com.github.johnrengelman.shadow: 7.1.0 com.github.johnrengelman.shadow: 7.1.0
com.github.ben-manes.versions: 0.36.0 com.github.ben-manes.versions: 0.36.0
org.jlleitschuh.gradle.ktlint: &ktlint 10.2.0
versions: versions:
kotlin: &kotlin 1.5.31
dokka: *kotlin
checkerQual: 3.14.0 checkerQual: 3.14.0
# build-logic # build-logic
@ -15,6 +18,7 @@ versions:
gradleTestLogger: 3.0.0 gradleTestLogger: 3.0.0
gradleErrorprone: 2.0.2 gradleErrorprone: 2.0.2
licenser: 0.6.1 licenser: 0.6.1
ktlint: *ktlint
dependencies: dependencies:
checkerQual: checkerQual:
@ -43,5 +47,17 @@ dependencies:
group: net.ltgt.gradle group: net.ltgt.gradle
name: gradle-errorprone-plugin name: gradle-errorprone-plugin
version: { ref: gradleErrorprone } 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: bundles:

View file

@ -22,8 +22,9 @@ include(":cloud-services")
include(":cloud-tasks") include(":cloud-tasks")
include(":cloud-annotations") include(":cloud-annotations")
// Extension Modules // Kotlin Extensions
include(":cloud-kotlin-extensions") setupKotlinModule("cloud-kotlin-extensions")
setupKotlinModule("cloud-kotlin-coroutines-annotations")
// Discord Modules // Discord Modules
setupDiscordModule("cloud-javacord") setupDiscordModule("cloud-javacord")
@ -59,6 +60,9 @@ fun setupDiscordModule(name: String) =
fun setupMinecraftModule(name: String) = fun setupMinecraftModule(name: String) =
setupSubproject(name, file("cloud-minecraft/$name")) setupSubproject(name, file("cloud-minecraft/$name"))
fun setupKotlinModule(name: String) =
setupSubproject(name, file("cloud-kotlin/$name"))
fun setupExampleModule(name: String) = fun setupExampleModule(name: String) =
setupSubproject(name, file("examples/$name")) setupSubproject(name, file("examples/$name"))