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

KSP2 Generated .class files are not added to the classpath #2365

Open
dstepanov opened this issue Mar 6, 2025 · 2 comments
Open

KSP2 Generated .class files are not added to the classpath #2365

dstepanov opened this issue Mar 6, 2025 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@dstepanov
Copy link
Contributor

dstepanov commented Mar 6, 2025

I'm trying to migrate Micronaut to use use Kotlin 2 and KSP2.

I see the files are generated but classes cannot be loaded by Class.forName.

Do you have any idea what can be wrong?

Reading the class as file getClass().getClassLoader().getResource(className.replace('.', '/').concat(".class")) doesn't work. It looks like classes are not included on the classpath but the resources are added.

@ting-yuan ting-yuan added the bug Something isn't working label Mar 6, 2025
@ting-yuan ting-yuan added this to the 1.0.32 milestone Mar 13, 2025
@ting-yuan
Copy link
Collaborator

Can you share more details on how / when the classes are generated and how / when they are loaded? E.g., are you loading the classes generated in a previous round, different Gradle tasks or different Gradle modules, etc.

@dstepanov
Copy link
Contributor Author

We use this call to write a class:

codeGenerator.createNewFile(
            getNativeElements(classname, originatingElements),
            classname.substringBeforeLast('.'),
            classname.substringAfterLast('.'),
            "class")

And we expect those classes to be present on the runtime classpath at the same module.

Micronaut annotation processor processes beans definitions etc. and generates metadata bean definitions classes that are loaded at the runtime using the service loader feature to create the bean context. Currently the service loader META-INF definitions are present at the classpath but not the generated classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants