指定注释处理器的顺序 [英] Specifying order of annotation processors
问题描述
我正在尝试在Java项目上运行Dagger 2和Lombok。当然,龙目岛必须首先运行,但实际上它是否真的有机会。起初我怀疑我可以通过类路径中库jar的相应位置来指定顺序,但是该顺序显然会被忽略。
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 suspected I could specify the order by the respective position of the library jars in the class path, but that order evidently gets ignored.
有没有办法指定他们以某种方式运行的顺序,或者我只能忍受不能组合两个AP?
Is there a way to specify the order for them to run somehow, or do I simply have to live with not being able to combine two APs ?
我已经产生了 SSCCE测试用例。
一个简单的 git clone
& mvn compile
足以证明这个问题 - 如果您在App.java中注释第18行并取消注释第20-21行,它将编译,即使第18行中的Lombok符号创建一个相同的构造函数。问题是Lombok似乎在Dagger之后运行。
A simple git clone
& mvn compile
is enough to demonstrate the issue - if you comment line 18 and uncomment lines 20-21 in App.java, it will compile, even though the Lombok notation in line 18 creates an identical constructor. The problem is that Lombok seems to run after Dagger.
推荐答案
经过大量研究并与其中一位Lombok开发人员交谈过,事实证明,因为javac基于hashCode()进行类加载,在这种情况下运行的注释处理器的顺序基本上是随机的,更糟糕的是,在多次运行之间随机。目前似乎没有这个问题的解决方案。
After a lot of research and having talked to one of the Lombok developers, it turns out that because javac does class loading based on hashCode(), the order of annotation processors running in this scenario is essentially random, and what's worse, random between multiple runs. There currently does not seem to be a solution to this issue.
我选择使用lombok-maven插件并整理整个事情,这不是完美的,有点hacky ,但至少产生一个工作结果。希望它可以帮助未来的googlers来到这里,我提交了工作版到回购。
I went with the lombok-maven plugin and delomboking the whole thing, which isn't perfect and somewhat hacky, but at least produces a working result. In hopes that it may aid future googlers coming here, I commited the working version to the repo.
这篇关于指定注释处理器的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!