Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新 Kotlin 至 v2.0.0 #830

Merged
merged 8 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/qodana_code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ jobs:

- name: 'Qodana Scan'
uses: JetBrains/qodana-action@main
with:
upload-result: true
github-token: ${{ secrets.FORLIY_ACCESS_TOKEN }}
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} # read the steps about it below
GITHUB_TOKEN: ${{ secrets.FORLIY_ACCESS_TOKEN }}



43 changes: 26 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import love.forte.gradle.common.core.project.setup
plugins {
idea
id("simbot.dokka-multi-module")
id("com.github.gmazzo.buildconfig") version "4.1.2" apply false
id("com.github.gmazzo.buildconfig") version "5.3.5" apply false
alias(libs.plugins.detekt)
id("simbot.nexus-publish")
id("simbot.changelog-generator")

// https://www.jetbrains.com/help/qodana/code-coverage.html
// https://github.com/Kotlin/kotlinx-kover
id("org.jetbrains.kotlinx.kover") version "0.7.6"
alias(libs.plugins.kotlinxKover)

alias(libs.plugins.kotlinxBinaryCompatibilityValidator)
}

setup(P.Simbot)
Expand Down Expand Up @@ -74,20 +75,6 @@ subprojects {
return@afterEvaluate
}

fun Project.hasKtP(): Boolean {
return plugins.findPlugin("org.jetbrains.kotlin.jvm") != null ||
plugins.findPlugin("org.jetbrains.kotlin.multiplatform") != null
}

if (hasKtP()) {
// apply(plugin = "io.gitlab.arturbosch.detekt")
// applyDetekt()
if ("gradle" !in name) {
useK2()
logger.info("Enable K2 for {}", this)
}
}

applyKover(root)
}

Expand All @@ -97,7 +84,7 @@ dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${libs.versions.detekt.get()}")
}

// config detekt
//region config detekt
detekt {
source.setFrom(subprojects.map { it.projectDir.absoluteFile })
config.setFrom(rootDir.resolve("config/detekt/detekt.yml"))
Expand Down Expand Up @@ -146,6 +133,28 @@ fun Project.applyKover(rp: Project) {
}
}
}
//endregion

apiValidation {
ignoredPackages.add("*.internal.*")

this.ignoredProjects.addAll(
listOf(
"interface-uml-processor",
"simbot-test",
)
)

// 实验性和内部API可能无法保证二进制兼容
nonPublicMarkers.addAll(
listOf(
"love.forte.simbot.annotations.ExperimentalSimbotAPI",
"love.forte.simbot.annotations.InternalSimbotAPI",
),
)

apiDumpDirectory = "api"
}

idea {
module {
Expand Down
15 changes: 8 additions & 7 deletions buildSrc/src/main/kotlin/JsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Project https://github.com/simple-robot/simpler-robot
* Email [email protected]
*
* This file is part of the Simple Robot Library.
* This file is part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -46,7 +46,7 @@ inline fun KotlinJsTargetDsl.configJs(

if (browser) {
browser {
testTask{
testTask {
useKarma {
useChromeHeadless()
// useConfigDirectory(File(project.rootProject.projectDir, "karma"))
Expand All @@ -71,19 +71,20 @@ fun Project.configJsTestTasks() {
}
}

@Suppress("UNUSED_PARAMETER")
inline fun KotlinWasmJsTargetDsl.configWasmJs(
nodeJs: Boolean = true,
browser: Boolean = true,
block: () -> Unit = {}
) {
if (nodeJs && isLinux) {
// if (nodeJs && isLinux) {
// win in candy node `21.0.0-v8-canary202309143a48826a08` is not supported
// nodejs()
}
// }

if (browser) {
browser {
testTask{
testTask {
useKarma {
useChromeHeadless()
// useConfigDirectory(File(project.rootProject.projectDir, "karma"))
Expand All @@ -101,8 +102,8 @@ inline fun Project.configWasmJsTest(block: () -> Unit = {}) {
// see https://youtrack.jetbrains.com/issue/KT-63014/Running-tests-with-wasmJs-in-1.9.20-requires-Chrome-Canary#focus=Comments-27-8321383.0-0
rootProject.the<NodeJsRootExtension>().apply {
// nodeVersion = "21.0.0-v8-canary202309143a48826a08"
nodeVersion = "21.0.0-v8-canary202309143a48826a08"
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
version = "21.0.0-v8-canary202309143a48826a08"
downloadBaseUrl = "https://nodejs.org/download/v8-canary"
}

tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {
Expand Down
15 changes: 8 additions & 7 deletions buildSrc/src/main/kotlin/JvmConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName
import org.gradle.kotlin.dsl.withType
import org.gradle.process.CommandLineArgumentProvider
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget


@OptIn(ExperimentalKotlinGradlePluginApi::class)
inline fun KotlinJvmTarget.configJava(crossinline block: KotlinJvmTarget.() -> Unit = {}) {
withJava()
compilations.all {
kotlinOptions {
javaParameters = true
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all")
}
compilerOptions {
javaParameters.set(true)
freeCompilerArgs.addAll(
"-Xjvm-default=all"
)
}

testRuns["test"].executionTask.configure {
Expand Down Expand Up @@ -75,7 +76,7 @@ inline fun KotlinJvmProjectExtension.configKotlinJvm(
) {
configJavaToolchain(jdkVersion)
compilerOptions {
javaParameters = true
javaParameters.set(true)
jvmTarget.set(JvmTarget.fromTarget(jdkVersion.toString()))
// freeCompilerArgs.addAll("-Xjvm-default=all", "-Xjsr305=strict")
freeCompilerArgs.set(freeCompilerArgs.getOrElse(emptyList()) + listOf("-Xjvm-default=all", "-Xjsr305=strict"))
Expand Down
12 changes: 3 additions & 9 deletions buildSrc/src/main/kotlin/K2Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@
*/

import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType


@Deprecated("Kt is already applied")
@Suppress("UNUSED_PARAMETER", "UnusedReceiverParameter")
fun Project.useK2(languageVersion: String = "2.0") {
logger.warn("暂时关闭K2, 等待稳定版。The input languageVersion = {}", languageVersion)
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
// useK2
// TODO 暂时关闭,等待 Kt2.0
// this.languageVersion = languageVersion
}
}
// Nothing.
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ sealed class P(override val group: String) : ProjectDetail() {
val versionWithoutSnapshot: Version

init {
val mainVersion = version(4, 0, 0) - version("beta3")
val mainVersion = version(4, 0, 0) - version("RC1")

fun initVersionWithoutSnapshot(status: Version?): Version = if (status == null) {
mainVersion
Expand Down
22 changes: 16 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[versions]
kotlin = "1.9.23"
kotlin = "2.0.0"
dokka = "1.9.20"
kotlinx-coroutines = "1.8.0"
kotlinx-coroutines = "1.8.1"
kotlinx-serialization = "1.6.3"
spring-boot-v2 = "2.7.18"
spring-boot-v3 = "3.2.1"
openjdk-jmh = "1.36"
ktor = "2.3.8"
slf4j = "2.0.12"
ksp = "1.9.23-1.0.19"
# https://kotlinlang.org/docs/ksp-quickstart.html
# https://github.com/google/ksp
ksp = "2.0.0-1.0.21"
# https://square.github.io/kotlinpoet/
kotlinPoet = "1.16.0"
# https://github.com/Kotlin/kotlinx-benchmark
kotlinxBenchmark = "0.4.10"
reactor = "3.6.2"
# simbots
suspendTransform = "0.7.0-beta1"
suspendTransform = "0.8.0-beta1"
suspendReversal = "0.2.0"
gradleCommon = "0.2.0"
gradleCommon = "0.3.0"
# tests
mockk = "1.13.10"
# detekt
Expand All @@ -26,7 +28,7 @@ detekt = "1.23.3"

[libraries]
# jetbrains-annotation
jetbrains-annotations = "org.jetbrains:annotations:24.0.1"
jetbrains-annotations = "org.jetbrains:annotations:24.1.0"

# dokka
dokka-plugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "dokka" }
Expand Down Expand Up @@ -135,11 +137,19 @@ mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
# benchmark
kotlinx-benchmark-runtime = { group = "org.jetbrains.kotlinx", name = "kotlinx-benchmark-runtime", version.ref = "kotlinxBenchmark" }


[plugins]
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
kotlinxBenchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinxBenchmark" }
kotlinAllOpen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
# Kover
# https://www.jetbrains.com/help/qodana/code-coverage.html
# https://github.com/Kotlin/kotlinx-kover
kotlinxKover = { id = "org.jetbrains.kotlinx.kover", version = "0.8.0" }
# binary-compatibility-validator
# https://github.com/Kotlin/binary-compatibility-validator
kotlinxBinaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.15.0-Beta.2" }

[bundles]
gradle-common = ["gradle-common-core", "gradle-common-multiplatform", "gradle-common-publication"]
Expand Down
Loading
Loading