rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

Generated types not visible to IntelliJ

Open cgruber opened this issue 1 year ago • 4 comments

When running kotlin in IntelliJ, code that is generated in either ksp or kapt processors (e.g. dagger, or custom ksp) are not attached in a way that IJ can see them. They compile, but redline. This also has the effect of making the generated sources un-findable by the IDE.

Related: ksp-generated sources are not visible under bazel-out. kapt-generated sources are, under bazel-bin/path/to/library/_javac/lib/lib-java_tmp/path/to/library/GeneratedFile.java. .kt files generated by KSP are available in the deep directories, but not attached anywhere within bazel-out, so they can't even be navigated to from within the project.

While this is strictly an IntelliJ Bazel plugin issue, it seems to likely be an issue with various aspects and what info attached during rules_kotlin related actions. I'm not sure how to better describe this, but can dig into it with anyone, with examples.

cgruber avatar Jan 19 '24 20:01 cgruber

@restingbull is a comedian

cgruber avatar Jan 19 '24 23:01 cgruber

Adding something like this to the BUILD that uses the kt_ksp_plugin "fixed" it for me:

java_plugin(
    name = "convince_intellij_this_module_generates_code",
    srcs = ["Empty.java"],
    generates_api = True,
)

henrikpersson avatar May 24 '24 15:05 henrikpersson

Bump this thread 😄 Does anyone have a plan to implement this feature?

dvpermyakov avatar Jul 29 '24 09:07 dvpermyakov

Yeah I am encountering this issue trying to use the koin ksp compiler for annotation processing. I have something similar to

kt_ksp_plugin(
    name = "koin_codegen",
    processor_class = "org.koin.compiler.BuilderProcessor",
    deps = [
        "@maven//:io_insert_koin_koin_ksp_compiler_jvm",
    ],
)

kt_jvm_library(
    name = "generated_koin",
    srcs = glob(["src/main/kotlin/**"]),
    plugins = [":koin_codegen"],
    deps = _DEPS,
)

which produces a generated_koin.jar correctly in bazel-bin/path/to/package but Intellij does not add this jar to the external libraries list when another lib adds it as a dep and you cannot use it properly in ij.

th0masb avatar Aug 07 '24 14:08 th0masb