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

Add support for KSP annotation processing via KspCompile #955

Merged

Conversation

Bencodes
Copy link
Collaborator

@Bencodes Bencodes commented Apr 12, 2023

Adding proper support for KSP annotation processors.

KSP plugins can be defined and given to targets using the kt_ksp_plugin rule and can be passed to Kotlin targets in the plugins attribute.

With this approach KSP and Kapt can be used in the same module.

Example:

kt_ksp_plugin(
    name = "moshi-kotlin-codegen",
    processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider",
    deps = [
        "@maven//:com_squareup_moshi_moshi",
        "@maven//:com_squareup_moshi_moshi_kotlin",
        "@maven//:com_squareup_moshi_moshi_kotlin_codegen",
    ],
)

kt_jvm_library(
    name = "lib",
    srcs = glob(["*.kt"]),
    plugins = ["//:moshi-kotlin-codegen"],
)

@Bencodes
Copy link
Collaborator Author

Waiting for this to land so that we can properly find runfiles #956

@Bencodes Bencodes force-pushed the add-support-for-ksp-annotation-processing-via-kspcompile branch from b1c4ecb to 6749c40 Compare April 20, 2023 20:03
@Bencodes Bencodes force-pushed the add-support-for-ksp-annotation-processing-via-kspcompile branch from 6749c40 to 3a552f0 Compare April 20, 2023 21:01
@Bencodes Bencodes force-pushed the add-support-for-ksp-annotation-processing-via-kspcompile branch from d073c82 to 311e727 Compare April 20, 2023 21:25
transitive_runtime_jars = transitive_runtime_jars,
plugins = plugins,
outputs = {
"ksp_generated_java_srcjar": ksp_generated_java_srcjar,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This action currently only supports collecting generated Kotlin source files and resources. If a KSP plugin outputs Java or compiled outputs, this action will not collect them up to be used in the downstream actions.

"incremental" to listOf("false"),
// Directory where class files are written to. Files written to this directory are class
// files being written directly from the annotation processor, not Kotlinc
"classOutputDir" to listOf(directories.generatedClasses),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

classOutputDir, javaOutputDir, and javaOutputDir are currently being ignored when written to. We'll need to look into adding support for this incrementally.

@@ -19,12 +19,23 @@ java_plugin(
deps = ["@maven//:com_google_auto_value_auto_value"],
)

kt_ksp_plugin_info(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not kt_ksp_plugin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah good catch. Renamed this to just kt_ksp_plugin

@Bencodes Bencodes merged commit f92d4b7 into master Apr 21, 2023
@Bencodes Bencodes deleted the add-support-for-ksp-annotation-processing-via-kspcompile branch April 21, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants