Plugin to AspectJ class weave Kotlin and Java code

I’m working on a plugin that does AspectJ post-compile class weaving of Java and Kotlin bytecode (something cringeworthy but I can’t really get AspectJ out of my company’s code so I might as well make it so that new kotlin code works the same as our Java code).

Gradle has the whole new “produce class files in a different directory per language” mentality, but when I do bytecode weaving I end up producing one directory with classes with the kotlin/java class files jumbled together.

I want to make sure that this plugin behaves correctly with how gradle does stuff with the java-library plugin as well as the rest of the ecosystem.

My current solution is to put all of the woven classes into the old directory compileJava.destinationDir and redirect the compileJava and compileKotlin into "${project.buildDir}/classes/java/preWeave" and "${project.buildDir}/classes/kotlin/preWeave" respectively.

I’m wondering if there is someone who can offer some suggestions about how to go about designing this plugin correctly.

Some specific concerns:

  • Potential pitfalls, that I could encounter.
  • Potential issues where the java-library plugin won’t recognize the woven classes.
  • How to make this weaving faster with incremental compilation support.

Tangentially related issues:

  • IntelliJ Ultimate doesn’t support AspectJ Post-Compile bytecode weaving for Kotlin (KT-20760)
  • Kotlin gradle compiler plugin doesn’t see woven classes as “friendly” (KT-20760)

Plugin current state:

1 Like