From 5582a0402d73a448ec8884f0c11b404215ef2215 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Sat, 13 Jan 2024 02:12:53 +0800 Subject: [PATCH] v0.6.0-beta4 --- buildSrc/src/main/kotlin/IProject.kt | 3 +- .../SuspendTransformCommandLineProcessor.kt | 3 +- .../build.gradle.kts | 5 +- .../src/main/kotlin/BuildConfig.kt | 32 ++++++++ .../forte/plugin/suspendtrans/gradle/DSL.kt | 4 +- .../gradle/SuspendTransformGradleExtension.kt | 5 +- .../gradle/SuspendTransformGradlePlugin.kt | 75 ++++++++++--------- 7 files changed, 83 insertions(+), 44 deletions(-) create mode 100644 plugins/suspend-transform-plugin-gradle/src/main/kotlin/BuildConfig.kt diff --git a/buildSrc/src/main/kotlin/IProject.kt b/buildSrc/src/main/kotlin/IProject.kt index 0e24e4f..aaabe9a 100644 --- a/buildSrc/src/main/kotlin/IProject.kt +++ b/buildSrc/src/main/kotlin/IProject.kt @@ -1,5 +1,6 @@ import love.forte.gradle.common.core.project.ProjectDetail import love.forte.gradle.common.core.project.Version +import love.forte.gradle.common.core.project.minus import love.forte.gradle.common.core.project.version object IProject : ProjectDetail() { @@ -8,7 +9,7 @@ object IProject : ProjectDetail() { const val DESCRIPTION = "Generate platform-compatible functions for Kotlin suspend functions" const val HOMEPAGE = "https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin" - override val version: Version = version(0, 6, 0) + override val version: Version = version(0, 6, 0) - version("beta4") override val homepage: String get() = HOMEPAGE diff --git a/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformCommandLineProcessor.kt b/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformCommandLineProcessor.kt index 496cba5..a269b67 100644 --- a/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformCommandLineProcessor.kt +++ b/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformCommandLineProcessor.kt @@ -1,6 +1,5 @@ package love.forte.plugin.suspendtrans -import BuildConfig import com.google.auto.service.AutoService import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor @@ -17,7 +16,7 @@ class SuspendTransformCommandLineProcessor : CommandLineProcessor { CompilerConfigurationKey.create(CliOptions.CONFIGURATION) } - override val pluginId: String = BuildConfig.KOTLIN_PLUGIN_ID + override val pluginId: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_ID override val pluginOptions: Collection = CliOptions.allOptions.map { it as SimpleCliOption } diff --git a/plugins/suspend-transform-plugin-gradle/build.gradle.kts b/plugins/suspend-transform-plugin-gradle/build.gradle.kts index 606dde4..e8f9670 100644 --- a/plugins/suspend-transform-plugin-gradle/build.gradle.kts +++ b/plugins/suspend-transform-plugin-gradle/build.gradle.kts @@ -34,10 +34,11 @@ dependencies { } buildConfig { + className("SuspendTransPluginConstants") useKotlinOutput { - internalVisibility = true + internalVisibility = false } - withoutPackage() + packageName("love.forte.plugin.suspendtrans.gradle") val project = project(":compiler:suspend-transform-plugin-embeddable") buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["kotlin_plugin_id"]}\"") diff --git a/plugins/suspend-transform-plugin-gradle/src/main/kotlin/BuildConfig.kt b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/BuildConfig.kt new file mode 100644 index 0000000..c75463e --- /dev/null +++ b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/BuildConfig.kt @@ -0,0 +1,32 @@ +import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants + +@Deprecated( + "Use SuspendTransPluginConstants", + ReplaceWith( + "SuspendTransPluginConstants", + imports = ["love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants"] + ) +) +internal object BuildConfig { + internal const val KOTLIN_PLUGIN_ID: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_ID + + internal const val PLUGIN_VERSION: String = SuspendTransPluginConstants.PLUGIN_VERSION + + internal const val KOTLIN_PLUGIN_GROUP: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_GROUP + + internal const val KOTLIN_PLUGIN_NAME: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_NAME + + internal const val KOTLIN_PLUGIN_VERSION: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_VERSION + + internal const val ANNOTATION_GROUP: String = SuspendTransPluginConstants.ANNOTATION_GROUP + + internal const val ANNOTATION_NAME: String = SuspendTransPluginConstants.ANNOTATION_NAME + + internal const val ANNOTATION_VERSION: String = SuspendTransPluginConstants.ANNOTATION_VERSION + + internal const val RUNTIME_GROUP: String = SuspendTransPluginConstants.RUNTIME_GROUP + + internal const val RUNTIME_NAME: String = SuspendTransPluginConstants.RUNTIME_NAME + + internal const val RUNTIME_VERSION: String = SuspendTransPluginConstants.RUNTIME_VERSION +} diff --git a/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/DSL.kt b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/DSL.kt index 1bae3d4..dc718ad 100644 --- a/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/DSL.kt +++ b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/DSL.kt @@ -2,8 +2,8 @@ package love.forte.plugin.suspendtrans.gradle -import BuildConfig.KOTLIN_PLUGIN_ID -import BuildConfig.PLUGIN_VERSION +import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants.KOTLIN_PLUGIN_ID +import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants.PLUGIN_VERSION val org.gradle.plugin.use.PluginDependenciesSpec.`suspend-transform`: org.gradle.plugin.use.PluginDependencySpec diff --git a/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradleExtension.kt b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradleExtension.kt index 88f342b..8ecc510 100644 --- a/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradleExtension.kt +++ b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradleExtension.kt @@ -1,6 +1,5 @@ package love.forte.plugin.suspendtrans.gradle -import BuildConfig import love.forte.plugin.suspendtrans.SuspendTransformConfiguration @@ -15,7 +14,7 @@ open class SuspendTransformGradleExtension : SuspendTransformConfiguration() { */ var includeAnnotation: Boolean = true - var annotationDependencyVersion: String = BuildConfig.ANNOTATION_VERSION + var annotationDependencyVersion: String = SuspendTransPluginConstants.ANNOTATION_VERSION /** * 当 [includeAnnotation] 为 true 时,配置runtime环境的依赖方式。默认为 `compileOnly` (在JVM中) 。 @@ -27,7 +26,7 @@ open class SuspendTransformGradleExtension : SuspendTransformConfiguration() { */ var includeRuntime: Boolean = true - var runtimeDependencyVersion: String = BuildConfig.RUNTIME_VERSION + var runtimeDependencyVersion: String = SuspendTransPluginConstants.RUNTIME_VERSION /** * 当 [includeRuntime] 为 true 时,配置runtime环境的依赖方式。默认为 `implementation` (在JVM中)。 diff --git a/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradlePlugin.kt b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradlePlugin.kt index 75c52a5..c86f9b9 100644 --- a/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradlePlugin.kt +++ b/plugins/suspend-transform-plugin-gradle/src/main/kotlin/love/forte/plugin/suspendtrans/gradle/SuspendTransformGradlePlugin.kt @@ -1,6 +1,5 @@ package love.forte.plugin.suspendtrans.gradle -import BuildConfig import love.forte.plugin.suspendtrans.CliOptions import org.gradle.api.Project import org.gradle.api.provider.Provider @@ -22,13 +21,13 @@ open class SuspendTransformGradlePlugin : KotlinCompilerPluginSupportPlugin { return kotlinCompilation.target.project.plugins.hasPlugin(SuspendTransformGradlePlugin::class.java) } - override fun getCompilerPluginId(): String = BuildConfig.KOTLIN_PLUGIN_ID + override fun getCompilerPluginId(): String = SuspendTransPluginConstants.KOTLIN_PLUGIN_ID override fun getPluginArtifact(): SubpluginArtifact { return SubpluginArtifact( - groupId = BuildConfig.KOTLIN_PLUGIN_GROUP, - artifactId = BuildConfig.KOTLIN_PLUGIN_NAME, - version = BuildConfig.KOTLIN_PLUGIN_VERSION + groupId = SuspendTransPluginConstants.KOTLIN_PLUGIN_GROUP, + artifactId = SuspendTransPluginConstants.KOTLIN_PLUGIN_NAME, + version = SuspendTransPluginConstants.KOTLIN_PLUGIN_VERSION ) } @@ -42,12 +41,12 @@ open class SuspendTransformGradlePlugin : KotlinCompilerPluginSupportPlugin { // val dependencies = project.dependencies // dependencies.add( // "compileOnly", -// "${BuildConfig.ANNOTATION_GROUP}:${BuildConfig.ANNOTATION_NAME}:${BuildConfig.ANNOTATION_VERSION}" +// "${SuspendTransPluginConstants.ANNOTATION_GROUP}:${SuspendTransPluginConstants.ANNOTATION_NAME}:${SuspendTransPluginConstants.ANNOTATION_VERSION}" // ) // if (extension.includeRuntime) { // dependencies.add( // extension.runtimeConfigurationName, -// "${BuildConfig.RUNTIME_GROUP}:${BuildConfig.RUNTIME_NAME}:${BuildConfig.RUNTIME_VERSION}" +// "${SuspendTransPluginConstants.RUNTIME_GROUP}:${SuspendTransPluginConstants.RUNTIME_NAME}:${SuspendTransPluginConstants.RUNTIME_VERSION}" // ) // } @@ -71,18 +70,23 @@ private fun Project.configureDependencies() { fun Project.include(platform: Platform, conf: SuspendTransformGradleExtension) { if (conf.includeAnnotation) { val notation = getDependencyNotation( - BuildConfig.ANNOTATION_GROUP, - BuildConfig.ANNOTATION_NAME, + SuspendTransPluginConstants.ANNOTATION_GROUP, + SuspendTransPluginConstants.ANNOTATION_NAME, platform, conf.annotationDependencyVersion ) - dependencies.add(conf.annotationConfigurationName, notation) + if (platform == Platform.JVM) { + dependencies.add(conf.annotationConfigurationName, notation) + } else { + // JS, native 似乎不支持其他的 name,例如 compileOnly + dependencies.add("implementation", notation) + } dependencies.add("testImplementation", notation) } if (conf.includeRuntime) { val notation = getDependencyNotation( - BuildConfig.RUNTIME_GROUP, - BuildConfig.RUNTIME_NAME, + SuspendTransPluginConstants.RUNTIME_GROUP, + SuspendTransPluginConstants.RUNTIME_NAME, platform, conf.runtimeDependencyVersion ) @@ -129,45 +133,48 @@ fun Project.withPluginWhenEvaluatedConf( fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtension) { if (rootProject.getBooleanProperty("kotlin.mpp.enableGranularSourceSetsMetadata")) { - val mainSourceSets = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets - .getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) - val testSourceSets = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets - .getByName(KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME) + val multiplatformExtensions = project.extensions.getByType(KotlinMultiplatformExtension::class.java) + val commonMainSourceSets = + multiplatformExtensions.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) + val commonTestSourceSets = + multiplatformExtensions.sourceSets.getByName(KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME) if (conf.includeAnnotation) { val notation = getDependencyNotation( - BuildConfig.ANNOTATION_GROUP, - BuildConfig.ANNOTATION_NAME, + SuspendTransPluginConstants.ANNOTATION_GROUP, + SuspendTransPluginConstants.ANNOTATION_NAME, Platform.MULTIPLATFORM, conf.annotationDependencyVersion ) - dependencies.add(mainSourceSets.compileOnlyConfigurationName, notation) - dependencies.add(testSourceSets.implementationConfigurationName, notation) + dependencies.add(commonMainSourceSets.compileOnlyConfigurationName, notation) + dependencies.add(commonTestSourceSets.implementationConfigurationName, notation) } if (conf.includeRuntime) { val notation = getDependencyNotation( - BuildConfig.RUNTIME_GROUP, - BuildConfig.RUNTIME_NAME, + SuspendTransPluginConstants.RUNTIME_GROUP, + SuspendTransPluginConstants.RUNTIME_NAME, Platform.MULTIPLATFORM, conf.annotationDependencyVersion ) - dependencies.add(mainSourceSets.implementationConfigurationName, notation) - dependencies.add(testSourceSets.implementationConfigurationName, notation) + dependencies.add(commonMainSourceSets.implementationConfigurationName, notation) + dependencies.add(commonTestSourceSets.implementationConfigurationName, notation) } // For each source set that is only used in Native compilations, add an implementation dependency so that it // gets published and is properly consumed as a transitive dependency: sourceSetsByCompilation().forEach { (sourceSet, compilations) -> - val isSharedNativeSourceSet = compilations.all { + val isSharedSourceSet = compilations.all { it.platformType == KotlinPlatformType.common || it.platformType == KotlinPlatformType.native + || it.platformType == KotlinPlatformType.js || it.platformType == KotlinPlatformType.wasm } - if (isSharedNativeSourceSet) { + + if (isSharedSourceSet) { if (conf.includeAnnotation) { val notation = getDependencyNotation( - BuildConfig.ANNOTATION_GROUP, - BuildConfig.ANNOTATION_NAME, + SuspendTransPluginConstants.ANNOTATION_GROUP, + SuspendTransPluginConstants.ANNOTATION_NAME, Platform.MULTIPLATFORM, conf.annotationDependencyVersion ) @@ -177,8 +184,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi if (conf.includeRuntime) { val notation = getDependencyNotation( - BuildConfig.RUNTIME_GROUP, - BuildConfig.RUNTIME_NAME, + SuspendTransPluginConstants.RUNTIME_GROUP, + SuspendTransPluginConstants.RUNTIME_NAME, Platform.MULTIPLATFORM, conf.annotationDependencyVersion ) @@ -215,8 +222,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi } val notation = getDependencyNotation( - BuildConfig.ANNOTATION_GROUP, - BuildConfig.ANNOTATION_NAME, + SuspendTransPluginConstants.ANNOTATION_GROUP, + SuspendTransPluginConstants.ANNOTATION_NAME, platform, conf.annotationDependencyVersion ) @@ -227,8 +234,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi val configurationName = sourceSet.implementationConfigurationName val notation = getDependencyNotation( - BuildConfig.RUNTIME_GROUP, - BuildConfig.RUNTIME_NAME, + SuspendTransPluginConstants.RUNTIME_GROUP, + SuspendTransPluginConstants.RUNTIME_NAME, platform, conf.runtimeDependencyVersion )