Pārlūkot izejas kodu

[build] Resolve compiler warnings in buildSrc

Him188 3 gadi atpakaļ
vecāks
revīzija
dca39f9b60

+ 11 - 4
buildSrc/build.gradle.kts

@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
+ * Copyright 2019-2023 Mamoe Technologies and contributors.
  *
  * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -16,7 +16,6 @@ repositories {
     google()
     mavenCentral()
     gradlePluginPortal()
-    maven("https://repo.mirai.mamoe.net/keep") // for modified shadow plugin
 }
 
 kotlin {
@@ -54,14 +53,22 @@ dependencies {
     // api("com.github.jengelman.gradle.plugins", "shadow", version("shadow"))
     api("com.github.johnrengelman", "shadow", version("shadow"))
 
-    api("org.jetbrains.kotlin", "kotlin-gradle-plugin", version("kotlinCompiler"))
+    api("org.jetbrains.kotlin", "kotlin-gradle-plugin", version("kotlinCompiler")) {
+        exclude("org.jetbrains.kotlin", "kotlin-stdlib")
+        exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
+        exclude("org.jetbrains.kotlin", "kotlin-reflect")
+    }
 //    api("org.jetbrains.kotlin", "kotlin-compiler-embeddable", version("kotlinCompiler"))
 //    api(ktor("client-okhttp", "1.4.3"))
     api("com.android.tools.build", "gradle", version("androidGradlePlugin"))
     api(asm("tree"))
     api(asm("util"))
     api(asm("commons"))
-    api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
+    api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") {
+        exclude("org.jetbrains.kotlin", "kotlin-stdlib")
+        exclude("org.jetbrains.kotlin", "kotlin-reflect")
+        exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
+    }
 
     api("gradle.plugin.com.google.gradle:osdetector-gradle-plugin:1.7.0")
 

+ 10 - 7
buildSrc/src/main/kotlin/HmppConfigure.kt

@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
+ * Copyright 2019-2023 Mamoe Technologies and contributors.
  *
  * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPI
 import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME
 import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
 import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
+import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
 import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
 import org.jetbrains.kotlin.gradle.plugin.mpp.*
 import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
@@ -159,7 +160,9 @@ fun Project.configureJvmTargetsHierarchical() {
         if (IDEA_ACTIVE) {
             jvm("jvmBase") { // dummy target for resolution, not published
                 compilations.all {
-                    this.compileKotlinTask.enabled = false // IDE complain
+                    this.compileTaskProvider.configure { // IDE complain
+                        enabled = false
+                    } 
                 }
                 attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) // magic
                 attributes.attribute(MIRAI_PLATFORM_ATTRIBUTE, "jvmBase") // avoid resolution
@@ -232,13 +235,13 @@ fun KotlinMultiplatformExtension.configureNativeTargetsHierarchical(
 
     val nativeMainSets = mutableListOf<KotlinSourceSet>()
     val nativeTestSets = mutableListOf<KotlinSourceSet>()
-    val nativeTargets = mutableListOf<KotlinNativeTarget>()
+    val nativeTargets = mutableListOf<KotlinTarget>() // actually KotlinNativeTarget, but KotlinNativeTarget is an internal API (complained by IDEA)
 
 
     fun KotlinMultiplatformExtension.addNativeTarget(
         preset: KotlinTargetPreset<*>,
-    ): KotlinNativeTarget {
-        val target = targetFromPreset(preset, preset.name) as KotlinNativeTarget
+    ): KotlinTarget {
+        val target = targetFromPreset(preset, preset.name) 
         nativeMainSets.add(target.compilations[MAIN_COMPILATION_NAME].kotlinSourceSets.first())
         nativeTestSets.add(target.compilations[TEST_COMPILATION_NAME].kotlinSourceSets.first())
         nativeTargets.add(target)
@@ -313,7 +316,7 @@ fun KotlinMultiplatformExtension.configureNativeTargetsHierarchical(
     }
 
     // Workaround from https://youtrack.jetbrains.com/issue/KT-52433/KotlinNative-Unable-to-generate-framework-with-Kotlin-1621-and-Xcode-134#focus=Comments-27-6140143.0-0
-    project.tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink>().configureEach {
+    project.tasks.withType<KotlinNativeLink>().configureEach {
         val properties = listOf(
             "ios_arm32", "watchos_arm32", "watchos_x86"
         ).joinToString(separator = ";") { "clangDebugFlags.$it=-Os" }
@@ -540,7 +543,7 @@ private fun Project.configureNativeInterop(
             }
         }
 
-        val generateKotlinBindings = tasks.register("generateKotlinBindings${compilationName.titlecase()}") {
+        tasks.register("generateKotlinBindings${compilationName.titlecase()}") {
             group = "mirai"
             description = "Generates Kotlin bindings for Rust"
             dependsOn(bindgen)

+ 4 - 6
buildSrc/src/main/kotlin/JvmPublishing.kt

@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
+ * Copyright 2019-2023 Mamoe Technologies and contributors.
  *
  * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -38,11 +38,9 @@ fun Project.configureRemoteRepos() {
         repositories {
             maven {
                 name = "MiraiStageRepo"
-                var stageRepoLoc = getLocalProperty("publishing.stage-repo")?.let(::File)
-                if (stageRepoLoc?.exists() != true) {
-                    stageRepoLoc = rootProject.file("ci-release-helper/stage-repo")
-                }
-                stageRepoLoc as File
+                val stageRepoLoc = getLocalProperty("publishing.stage-repo")?.let(::File)
+                    ?.takeIf { it.exists() }
+                    ?: rootProject.file("ci-release-helper/stage-repo")
 
                 url = stageRepoLoc.also { it.mkdirs() }.toURI()
             }

+ 8 - 5
buildSrc/src/main/kotlin/Relocation.kt

@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
+ * Copyright 2019-2023 Mamoe Technologies and contributors.
  *
  * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -101,7 +101,7 @@ fun KotlinDependencyHandler.relocateCompileOnly(
     }
     project.relocationFilters.add(
         RelocationFilter(
-            dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false,
+            dependency.groupNotNull, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false,
         )
     )
     // Don't add to runtime
@@ -125,7 +125,7 @@ fun DependencyHandler.relocateCompileOnly(
         })
     project.relocationFilters.add(
         RelocationFilter(
-            dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false,
+            dependency.groupNotNull, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false,
         )
     )
     // Don't add to runtime
@@ -149,7 +149,7 @@ fun KotlinDependencyHandler.relocateImplementation(
     }
     project.relocationFilters.add(
         RelocationFilter(
-            dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = true,
+            dependency.groupNotNull, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = true,
         )
     )
     project.configurations.maybeCreate(SHADOW_RELOCATION_CONFIGURATION_NAME)
@@ -184,7 +184,7 @@ fun DependencyHandler.relocateImplementation(
         })
     project.relocationFilters.add(
         RelocationFilter(
-            dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = true,
+            dependency.groupNotNull, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = true,
         )
     )
     project.configurations.maybeCreate(SHADOW_RELOCATION_CONFIGURATION_NAME)
@@ -201,6 +201,9 @@ fun DependencyHandler.relocateImplementation(
     return dependency
 }
 
+@Suppress("UNNECESSARY_NOT_NULL_ASSERTION") // compiler bug
+private val ExternalModuleDependency.groupNotNull get() = group!!
+
 private fun ExternalModuleDependency.intrinsicExclusions() {
     exclude(ExcludeProperties.`everything from kotlin`)
     exclude(ExcludeProperties.`everything from kotlinx`)

+ 3 - 3
buildSrc/src/main/kotlin/Shadow.kt

@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
+ * Copyright 2019-2023 Mamoe Technologies and contributors.
  *
  * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@@ -101,7 +101,7 @@ private fun KotlinTarget.configureRelocationForMppTarget(project: Project) = pro
         destinationDirectory.set(buildDir.resolve("libs")) // build/libs
         archiveBaseName.set("${project.name}-${targetName.toLowerCase()}") // e.g. "mirai-core-api-jvm"
 
-        dependsOn(compilations["main"].compileKotlinTask) // e.g. compileKotlinJvm
+        dependsOn(compilations["main"].compileTaskProvider) // e.g. compileKotlinJvm
 
         from(compilations["main"].output) // Add compilation result of mirai sourcecode, not including dependencies
         configuration?.let {
@@ -257,7 +257,7 @@ fun Project.registerRegularShadowTask(
         }
 
         val compilation = target.compilations["main"]
-        dependsOn(compilation.compileKotlinTask)
+        dependsOn(compilation.compileTaskProvider)
         from(compilation.output)
 
 //        components.findByName("java")?.let { from(it) }

+ 1 - 1
buildSrc/src/main/kotlin/Versions.kt

@@ -31,7 +31,7 @@ object Versions {
     val consoleIntellij get() = "223-$project-172-1" // idea-mirai-kotlin-patch
     val consoleTerminal get() = project
 
-    const val kotlinCompiler = "1.8.10"
+    const val kotlinCompiler = "1.8.20-RC"
     const val kotlinStdlib = kotlinCompiler
     const val dokka = "1.8.10"