tschuchortdev / kotlin-compile-testing

A library for testing Kotlin and Java annotation processors, compiler plugins and code generation
Mozilla Public License 2.0
667 stars 63 forks source link

How can I test multi-module annotation processing? #56

Open vinaygaba opened 4 years ago

vinaygaba commented 4 years ago

Not an issue per se but I was wondering how I can emulate a multi-module annotation processing setup where the processing runs separately for each module. I'd like to have some tests for this in particular as it's critical for my use case. Is this something that is already supported?

tschuchortdev commented 4 years ago

I think the logic you are trying to test happens on the Gradle level outside the scope of KotlinCompilation. K2JVMCompiler has no concept of modules (beyond project jigsaw) as far as I know, so you'd have to take a look at how Gradle deals with modules and then emulate that with separate KotlinCompilations. That would be very useful as an addon to KotlinCompilation (I can assist you if you want to go that route). Or you can try to create a Gradle project on-the-fly and then run that but you'd lose all the benefits that Kotlin-Compile-Testing provides.

vinaygaba commented 4 years ago

Thanks for your reply! I'll have to do a bit of reading to completely wrap my head around how all this fits together. Would appreciate if you have any pointers I could use!

tschuchortdev commented 4 years ago

AFAIK this stuff is completely undocumented and only passed on from person to person, so you will have to read the source code of the Kotlin Gradle Plugin or ask the authors. This could be useful as well: https://github.com/facebook/buck/tree/master/src/com/facebook/buck/jvm/kotlin

vinaygaba commented 4 years ago

Thank you for the recommendation!

bennyhuo commented 2 years ago

I am trying to add module support in this library: bennyhuo/kotlin-compile-testing-extensions, and it is used in bennyhuo/Mixin with a test data file Modules.kt.