Skip to content

[kapt] allow options to be passed to kapt and javac annotation processing. #1354

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

restingbull
Copy link
Collaborator

@restingbull restingbull commented Jul 18, 2025

Implements kapt_compiler_plugin, which allows the use of kt_plugin_cfg to pass option to annotation processors.

This is step one of moving kapt out of the builder, and enhancing the kt_compiler_plugin support.

Changes:

  • resolve_cfg signature change (no one is using it, as it's limited and complicated) to return a list of providers. This allows a compiler plugin to export configurations in a clearer manner.
  • Add annotation_processor_options to JavacOptions. This is not exposed on kt_javac_opts, as annotation_processor_options should always be associated with an annotation processor -- to avoid orphaned arguments being passed indefinitely. A rule could exploit this to make a mess, but that is on the author. I hope to avoid regretting this feature.
  • modify base64 args encoding to optimize on single argument values. The whole protocol for this in kapt is a right mess.
  • Fix javac annotation processing to include exported java plugins. Need better tests on this.
  • And a heavy bunch of test code. Some refactoring could make it less verbose.

Example:

This will add the undocumented argument com.google.auto.value.OmitIdentifiers to AutoValue processing. :autovalue_no_identifiers can be added to kt_jvm_library.plugins to trigger annotation processing.

kt_plugin_cfg(
    name = "autovalue_no_identifiers",
    options = {
        "com.google.auto.value.OmitIdentifiers": ["true"], # declare the OmitIdentifiers option value.
    },
    plugin = "//kotlin/compiler:kapt", # targets the configuration to kapt
    deps = [
        ":autovalue", # adds the AutoValue annotation processor to javac and kotlinc kapt
    ],
)

towards: #1311

@restingbull
Copy link
Collaborator Author

fyi: @shs96c, @cheister

@restingbull restingbull force-pushed the restingbull/kapt-as-plugin branch from 3ea44ed to 68f9515 Compare July 18, 2025 04:13
@restingbull restingbull force-pushed the restingbull/multiple-plugin-config branch 2 times, most recently from 6777456 to 6e9f8d0 Compare July 18, 2025 15:35
@restingbull restingbull force-pushed the restingbull/kapt-as-plugin branch 4 times, most recently from d0745fd to e791c19 Compare July 20, 2025 15:28
Base automatically changed from restingbull/multiple-plugin-config to master August 1, 2025 20:54
…sing.

java annotatin processing options can be passed like this:
```

kt_plugin_cfg(
    name = "autovalue_no_identifiers",
    options = {
        "com.google.auto.value.OmitIdentifiers": ["true"],
    },
    plugin = "//kotlin/compiler:kapt",
    deps = [
        ":autovalue",
    ],
)
```
@restingbull restingbull force-pushed the restingbull/kapt-as-plugin branch from e791c19 to c25e0fe Compare August 1, 2025 21:01
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