Oct 16, 2020

AspectJ and Kotlin

Getting AspectJ to work with Kotlin using post-compile weaving of Aspects and Mojo AspectJ Maven plugin.


Mojo AspectJ Maven plugin config


Nothing too special. The part that took me is the weaveDirectories. You want to weave the compiled class files that were generated using maven-compiler-plugin.
Generally speaking the idea is to use post-compile weaving of aspects. It’s a good idea to put the plugin definition last in the plugins directive. Definitely make sure it’s after the compilation. Also setting forceAjcCompile to true makes a difference.

No Java >8 support

Unfortunately there’s no support for Java >8 by the aspectj-maven-plugin plugin. There are unmerged pull requests if you really want to go for it.