-
Notifications
You must be signed in to change notification settings - Fork 232
Generate KSP classes jar as output #1329
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
base: master
Are you sure you want to change the base?
Generate KSP classes jar as output #1329
Conversation
@@ -145,6 +145,9 @@ class KotlinJvmTaskExecutor | |||
if (outputs.generatedKspSrcJar.isNotEmpty()) { | |||
context.execute("creating KSP generated src jar", ::createGeneratedKspKotlinSrcJar) | |||
} | |||
if (outputs.generatedKspClassesJar.isNotEmpty()) { | |||
context.execute("creating KSP generated classes jar", ::createdGeneratedKspClassesJar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be able to add some tests for this to KotlinJvmKspAssertionTest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to add tests with Micronaut because that'd require upgrading the repo to Java 17 (which introduces other breakages and probably out of scope for this PR). I'm not aware of other KSP processors that generate bytecode on the fly, so I wrote an example/dummy processor that generates class files and then added test cases to validate those class files are present in the final jar. Let me know if that works.
/** | ||
* An example KSP processor that generates bytecode to be used only for tests | ||
*/ | ||
class BytecodeGeneratorProcessor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was written purely for tests to validate the functionality.
Fixes #1328
Right now, the ksp generated src JAR has the generated sources and files from
META-INF/
. This doesn't suffice for KSP processors (Micronaut) which rely on generated .class files in annotation processing which isn't included in that jar now. We could include these files in that src jar but wasn't sure if it makes sense to include .class files, so I've added another output to theKotlinKsp
task which generates this jar and is then forwarded as one of the outputs of thekt_jvm_library
action.I'll test this internally and verify it fixes our issue. I wanted to add tests with Micronaut in
src/test
along with the existing KSP test cases, but Micronaut 4/KSP requires Java 17 which would require upgrading rules_kotlin to Java 17 which could be a breaking change for other users, so I didn't (let me know if I should). Instead I've added tests with a dummy processor that generates bytecode and updated the tests to verify the functionality.