Specifying order of annotation processors

前端 未结 3 880
庸人自扰
庸人自扰 2020-12-05 09:54

I\'m trying to run Dagger 2 as well as Lombok on my Java project. Lombok has to run first, of course, but whether it actually does seems to be up to chance. At first I suspe

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 10:36

    Ideally the order shouldn't matter. Annotation processors should only create files - whenever a file is created, another processing round starts and other processors have the chance again to do their thing with the new file. In this case the order doesn't really matter, so I don't think there is an official way to force an order of processors. The problem is that the Lombok processor manipulates existing files instead of creating new ones, which it is not supposed to do. Some compilers might have an option for ordering processors or use the order in which processors are loaded or appear in the command line arguments, but that will depend on the compiler's implementation.

    You could try looking at Daggers and Lombok's build process and see which processors are invoked there. Then explicitly set up those processors in your maven build in the correct order and test different compilers and see if any of them run them in this order.

    If necessary, you could split the compilation process and run Lombok with -proc:only first and after that another compilation step without Lombok and without overriding the manipulated files (if that is possible, I never tried that).

提交回复
热议问题