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

Support generating Java code with KSP #1074

Open
lukaciko opened this issue Nov 16, 2023 · 1 comment
Open

Support generating Java code with KSP #1074

lukaciko opened this issue Nov 16, 2023 · 1 comment

Comments

@lukaciko
Copy link
Contributor

As noted in the README, kt_ksp_plugin doesn't support generating Java code. Some annotation processors, like Dagger 2.48+, generate Java code and support KSP.


When implemented, updating examples/dagger to use KSP and building it should work:

diff --git a/examples/dagger/WORKSPACE b/examples/dagger/WORKSPACE
index 213945f..d74fe47 100644
--- a/examples/dagger/WORKSPACE
+++ b/examples/dagger/WORKSPACE
@@ -31,9 +31,9 @@ load("@rules_jvm_external//:defs.bzl", "maven_install")

 maven_install(
     artifacts = [
-        "com.google.dagger:dagger:2.45",
-        "com.google.dagger:dagger-compiler:2.45",
-        "com.google.dagger:dagger-producers:2.45",
+        "com.google.dagger:dagger:2.48",
+        "com.google.dagger:dagger-compiler:2.48",
+        "com.google.dagger:dagger-producers:2.48",
         "javax.inject:javax.inject:1",
         "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2",
     ],
diff --git a/examples/dagger/third_party/BUILD.bazel b/examples/dagger/third_party/BUILD.bazel
index e970b92..53ceec0 100644
--- a/examples/dagger/third_party/BUILD.bazel
+++ b/examples/dagger/third_party/BUILD.bazel
@@ -1,8 +1,8 @@
-load("@rules_java//java:defs.bzl", "java_library", "java_plugin")
+load("@rules_kotlin//kotlin:core.bzl", "kt_ksp_plugin")
+load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

-java_plugin(
+kt_ksp_plugin(
     name = "dagger_component_plugin",
-    generates_api = True,
     processor_class = "dagger.internal.codegen.ComponentProcessor",
     visibility = ["//visibility:private"],
     deps = [
@@ -10,9 +10,9 @@ java_plugin(
     ],
 )

-java_library(
+kt_jvm_library(
     name = "dagger",
-    exported_plugins = [":dagger_component_plugin"],
+    plugins = [":dagger_component_plugin"],
     visibility = ["//visibility:public"],
     exports = [
         "@maven//:com_google_dagger_dagger",
cd examples/dagger
bazelisk build coffee_app
@cgruber
Copy link
Collaborator

cgruber commented Nov 28, 2023

Oh cool! Dagger has initial KSP support. That's news to me. It does present a very tricky aspect, in that dagger still generates java, even when running in KSP. That's not a use-case I would have predicted.

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

No branches or pull requests

2 participants