Ksp does not process resources
I just tried the Micronaut example after generating a Micronaut launch for Gradle.
1 problem I'm bumping into is setting a flag in application.properties e.g. micronaut.openapi.json.format=true doesn't apply to KSP i.e. I don't get a json instead of yaml.
I tried the same in a default Gradle setup and it works.
It's basically just the Micronaut web app example in the docs with the properties file.
I wonder if it's due to it not picking up the resources directory or if something else is something. I'm using the default non-maven module option.
Thanks.
hello, reading through the docs, have you added the ksp processor of openapi ("io.micronaut.openapi:micronaut-openapi") in kotlinSymbolProcessors ? and it seems you may also need to add the "micronaut.openapi.project.dir" kspProcessorOptions
the resources with the non-maven module option should be in the top level resources/ directory , otherwise if they are in src/main/resources try to mix in the KotlinMavenModule
If you have a reproducible example it would be easier to troubleshoot
@vaslabs yes I've added the openapi library. The project dir is set. It also says if it is not set it will just create a dummy directory, so should be fine either way.
I tried the top level resources with an application.properties file.
thanks for the info @re-thc , I found some time today to test it, I think the issue with the properties file is that we don't pass it to the ksp
one workaround I've found is adding the flag to ksp processor options
for instance this is my added flag in the kotlin hello micronaut example
override def kspProcessorOptions: T[Map[String, String]] = Task {
super.kspProcessorOptions() ++ Map(
"micronaut.processing.module" -> moduleSegments.render,
"micronaut.processing.incremental" -> "true",
"micronaut.openapi.json.format" -> "true"
)
}
for a similar behaviour with gradle I need some more time to check how it behaves. I did try to pass the resources in the kspClasspath but it didn't work
@vaslabs thanks for the workaround. I also did some testing and it might not be ksp specific. Seems to not work with Java annotation processors too.
I'd expect adding the same flag to annotationProcessorsJavacOptions should work, e.g.
override def annotationProcessorsJavacOptions = super.annotationProcessorsJavacOptions() ++ Seq(
"-Amicronaut.processing.incremental=true",
"-Amicronaut.processing.group=example.micronaut",
"-Amicronaut.processing.module=todo",
"-Amicronaut.processing.annotations=example.micronaut.*",
"-Amicronaut.openapi.json.format=true"
)
EDIT: just tested
Do properties files get read at all? I'm not sure it's an annotation processor or ksp issue. Is there a bigger issue at hand to do with not reading the config from resources? I just tried a non-kip setting and the application won't pick it up either. A 1.3 change maybe?
Do properties files get read at all? I'm not sure it's an annotation processor or ksp issue. Is there a bigger issue at hand to do with not reading the config from
resources? I just tried a non-kip setting and the application won't pick it up either. A 1.3 change maybe?
there are examples under test that depend on the properties files to be picked up (e.g. for the port) , so I think that part is working .
The question is "when" these properties files should be read? The JavaModule.resources task does contain runtime-resources. If you need resources at compile-time, you need to use JavaModule.compileResources (associated to compile-resources dir by default).
I think conceptually, the equivalent of doing this in mill , would be to add the openapi.properties file in compile-resources directory.
I'll give it a go
didn't work with compile resources but another way of doing it with a file is:
following this guide for the official gradle setup
I think these are taken care of by the micronaut plugin
plugins {
id("io.micronaut.application") version "4.6.1"
...
}
in gradle, but there isn't an out of the box micronaut plugin in Mill, so some things need to be wired in like this