I am trying to write a custom task that should execute an annotation processor using
kapt now I know that it should be done automatically but I am facing a specific problem:
- I have a multi modules project where modules depend on each others (it’s dynamic and my plugin doesn’t know anything about the dependency)
- I have to run
kapt tasks from all modules before any compilation is invoked. I have tried
dependsOn but it seems like
kaptDebugKotlin task declares a dependency on
compileDebugKotlin (mustRunAfter kind of dependency), this means that once
kapt task from a module is done that task will be executed immediately. The problem occurs when the compilation process takes place and fails because some sources from another module (which should be generated by kapt) are not generated yet.
My problem is simple to explain so in short I need to know a way to Execute all
kapt tasks from all modules right when the build starts.
Any help please??
Just to make sure that I understand you correctly: You have a module structure something like
Module B: depends on Module A
But you need to access the generated sources from module B in module A?
I’m not sure this is possible. There is one way I could think of that might work though. Firstly all the sources you generate using kapt can’t depend on any code inside your modules. Then you can use
kaptGenerateStubs. You would then need to combine those stubs from all the modules and find a way to execute the main task of kapt on them. Kapt is based on the java annotation processor. If I understand it correctly it creates java stubs form kotlin code(
kaptGenerateStubs task) and then just calls the java annotation processor. You might need to take a look at the kapt sources to figure out how to do that(https://github.com/JetBrains/kotlin).
You should also join the kotlin slack(https://kotl.in/slack). You have a better chance to get help there from someone that understands the internals of the kotlin compiler and/or kapt tool.