Search code examples
javaannotationsannotation-processing

Testing of annotation processor in java


I am developing an annotation processor and now I doing next steps for testing:

  1. commit and push changes to github
  2. use jitpack for build and publish processor
  3. refresh gradle in Idea. build.gradle in my test project:
repositories {
    maven { url 'https://jitpack.io' }
}
configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
    compileOnly 'com.github.hohserg1:MyAnnotationProcessor:main-SNAPSHOT'
}
  1. try to build

It very terrible. How to reduce it to "press run button"?


Solution

  • You would need your processor, your annotation, and the application to be each in a different module is a different dependency, you do this to avoid cyclic dependency between the processor and the application, and also help you to avoid including the processor classes in your application artifacts.

    also, note that when you develop an annotation processor you don't test the processor itself but you test the code generated from that processor if the generated code works then the processor is also working as expected.