Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

java - Specifying order of annotation processors

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.

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 ?

I have produced an SSCCE test case.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...