Skip to content

Refactor and update Gradle plugin APIs and configurations #93

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

Merged
merged 21 commits into from
Apr 19, 2025

Conversation

ForteScarlet
Copy link
Owner

@ForteScarlet ForteScarlet commented Apr 15, 2025

This pr refactoring and updates the Gradle plugin configurations and APIs. Key changes include:

  • Refactored SuspendTransformConfiguration for better structure and readability.

Configuration and CLI options are extracted as separate modules, which should solve #90.

  • Deprecated legacy Gradle extension (SuspendTransformGradleExtension) and redirected usage to the new SuspendTransformPluginExtension.
-suspendTransform {
+suspendTransformPlugin {
    // ...
}

Past extensions are exposed to the public via data class. It's not conducive to maintenance and updates, and it's not “Gradle” enough.

The old suspendTransform { ... } DSL API is now deprecated and a new suspendTransformPlugin { ... } DSL API is provided. The new API uses Gradle's Property API and uses it as a bridge to hide the true compiler plugin configuration type for possible future extensions.

The new usage examples have been updated in the README.

Past:

suspendTransform {
    enabled = true
    includeAnnotation = true
    includeRuntime = true
    
    useDefault()
}

Now:

suspendTransformPlugin {
    enabled = true
    includeAnnotation = true
    includeRuntime = true
    
    transformers {
        useDefault()
    }
}

In addition, the Kotlin builds and dependencies of the cli, configuration, and gradle-plugin modules have been tweaked along the way (Language version down to KOTLIN_1_9, dependencies e.g. kotlin-stdlib down to 1.9.0), so they can now continue to be used in Gradle's buildSrc and the like.

Since Gradle has a built-in version of Kotlin and a relatively low version, in previous versions the compiler plugin has relied on a version of the Kotlin language that exceeds Gradle's built-in version, rendering it unusable in buildSrc.

Warning

Absolute binary compatibility with the previous is not guaranteed. But the source code SHOULD BE compatible.
The generated code is theoretically unaffected.

close #90
close #92
close #81

Reorganized Gradle plugin structure by introducing a separate module for deprecated configurations. Deprecated `SuspendTransformGradleExtension`, redirecting users to `SuspendTransformPluginExtension`. Added compatibility handling to maintain backward support while preparing for full removal of deprecated features.
Reorganized plugin configuration by refactoring `SuspendTransformConfiguration` to improve modularity and readability. The README_CN was updated for enhanced documentation and clarity.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors and updates the Gradle plugin APIs and configurations to provide a more maintainable and modern DSL for suspend transform configuration. Key changes include updating package imports and configuration keys, refactoring the transformation logic (in both FIR and IR components), and deprecating legacy configuration APIs in favor of a new, DSL-driven approach.

Reviewed Changes

Copilot reviewed 44 out of 48 changed files in this pull request and generated no comments.

Show a summary per file
File Description
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/ir/SuspendTransformIrGenerationExtension.kt Updated import path for SuspendTransformConfiguration to the new configuration module.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt Refactored transformer symbol maps, adjusted predicate handling, and removed the legacy check for non-null className in transform function info.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirExtensionRegistrar.kt Updated import for configuration and reformatted class declaration.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformComponentRegistrar.kt Adjusted dependencies with additional configuration imports and updated resolve logic.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformCommandLineProcessor.kt Replaced legacy configuration key with the new one and merged configuration updates using the plus operator.
compiler/suspend-transform-plugin-deprecated-configuration/src/main/kotlin/love/forte/plugin/suspendtrans/DeprecatedSuspendTransformConfiguration.kt Added deprecation annotations with guidance to use the new configuration API.
compiler/suspend-transform-plugin-cli Introduced new CLI modules for encoding/decoding configuration and updated associated README files.
buildSrc/src/main/kotlin/IProject.kt Bumped the plugin version as part of the refactoring effort.
Files not reviewed (4)
  • compiler/suspend-transform-plugin-cli/build.gradle.kts: Language not supported
  • compiler/suspend-transform-plugin-configuration/build.gradle.kts: Language not supported
  • compiler/suspend-transform-plugin-deprecated-configuration/build.gradle.kts: Language not supported
  • compiler/suspend-transform-plugin/build.gradle.kts: Language not supported
Comments suppressed due to low confidence (2)

compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt:114

  • The removal of the error check for a non-null className might allow transformer functions to be configured incorrectly. If this change is intentional, please add a clarifying comment or documentation entry to explain the updated behavior.
val className = transformFunctionInfo.className

compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformCommandLineProcessor.kt:35

  • [nitpick] The merging of configurations using the plus operator is not immediately obvious. Consider adding an inline comment or referencing documentation to clarify how configuration merging is expected to work.
if (SuspendTransformCliOptions.CLI_CONFIGURATION.optionName == option.optionName) {

@ForteScarlet
Copy link
Owner Author

PR waits to consider merging it after testing it with other local application projects.

@ForteScarlet
Copy link
Owner Author

simbot core 本地尝试迁移后未出现二进制变化,大致可以确认配置迁移后行为一致。稍后再试试各组件。
但是出现一个新问题:在进行复杂配置时,XxxSpec 的可复用程度变低了。

@ForteScarlet ForteScarlet requested a review from Copilot April 19, 2025 16:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors and updates the Gradle plugin APIs and configurations by introducing a new DSL API (suspendTransformPlugin) and improving the internal configuration mapping and CLI option handling. Key changes include:

  • Renaming and restructuring of DSL and configuration classes for improved readability and future extensibility.
  • Extraction of configuration and CLI options into separate modules with updated serialization and deprecation support.
  • Updates to test coverage and build scripts reflecting the new plugin version.

Reviewed Changes

Copilot reviewed 48 out of 52 changed files in this pull request and generated no comments.

Show a summary per file
File Description
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt Adjusts transformer symbol mapping, updates FIR transformation logic, and modifies origin handling.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirExtensionRegistrar.kt Updates imports and class declaration to conform to new configuration package structure.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformUserData.kt Updates import to use the new configuration package.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformComponentRegistrar.kt Modifies configuration resolution and adds deprecation comments for legacy code.
compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformCommandLineProcessor.kt Revises CLI option processing including updating the configuration key and merging configurations.
compiler/suspend-transform-plugin-deprecated-configuration/src/main/kotlin/love/forte/plugin/suspendtrans/DeprecatedSuspendTransformConfiguration.kt Adds deprecation annotations and helpful replacement suggestions for legacy configurations.
compiler/suspend-transform-plugin-deprecated-configuration/src/main/kotlin/love/forte/plugin/suspendtrans/CliOptions.kt Marks legacy CLI options as deprecated with updated warnings.
compiler/suspend-transform-plugin-deprecated-configuration/README.md Documents the purpose of the deprecated configuration module for transitional support.
compiler/suspend-transform-plugin-cli/src/test/kotlin/love/forte/plugin/suspendtrans/cli/ConfigurationSerializeTests.kt Introduces tests to verify configuration serialization and deserialization.
compiler/suspend-transform-plugin-cli/src/main/kotlin/love/forte/plugin/suspendtrans/cli/SuspendTransformCliOptions.kt Adds a new CLI option definition for configuration serialization.
compiler/suspend-transform-plugin-cli/src/main/kotlin/love/forte/plugin/suspendtrans/cli/SuspendTransformCliOption.kt Provides a new implementation for CLI options conversion and abstraction.
compiler/suspend-transform-plugin-cli/src/main/kotlin/love/forte/plugin/suspendtrans/cli/KotlinCompilerPluginCliOptions.kt Introduces new CLI options for the Kotlin compiler plugin.
compiler/suspend-transform-plugin-cli/src/main/kotlin/love/forte/plugin/suspendtrans/cli/GradlePluginCliOptions.kt Updates encoding/decoding logic for CLI options in the Gradle plugin module.
compiler/suspend-transform-plugin-cli/README.md Adds documentation for the CLI options module.
buildSrc/src/main/kotlin/IProject.kt Updates plugin version information to reflect the new release version.
buildSrc/src/main/kotlin/GradleSupportHelper.kt Adds a helper function ensuring Gradle buildSrc compatibility with updated Kotlin compiler versions.
Files not reviewed (4)
  • compiler/suspend-transform-plugin-cli/build.gradle.kts: Language not supported
  • compiler/suspend-transform-plugin-configuration/build.gradle.kts: Language not supported
  • compiler/suspend-transform-plugin-deprecated-configuration/build.gradle.kts: Language not supported
  • compiler/suspend-transform-plugin/build.gradle.kts: Language not supported

@ForteScarlet ForteScarlet merged commit 5b3175b into dev Apr 19, 2025
4 checks passed
@ForteScarlet ForteScarlet deleted the improve-cli-options branch April 19, 2025 16:35
@RTAkland
Copy link

直接就重构了😨

@ForteScarlet
Copy link
Owner Author

直接就重构了😨

包的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants