maven-compiler-plugin icon indicating copy to clipboard operation
maven-compiler-plugin copied to clipboard

[MCOMPILER-532] compile doesn't work without first clean with Dagger annotation processor

Open jira-importer opened this issue 2 years ago • 0 comments

Marquis Wang opened MCOMPILER-532 and commented

I have a reproducing example here: https://github.com/marquiswang/incremental-compile-dagger-test. The README there shows how it goes wrong.

Long story short, if you use mvn compile on a project with Dagger, touch the @Injected files, then do mvn compile again, then it will not correctly compile the Dagger-generated factory methods. You need to do a mvn clean compile.

I am pretty sure that this is because of how maven-compiler-plugin and javac interact with Dagger.

maven-compiler-plugin will, if it detects that a file has changed, delete compiled class files and recompile every class in the module. However, it does not delete target/generated-sources/annotations/. It calls javac on the Foo.java.

Dagger chooses not to re-generate the Foo_Factory.java file, presumably because it already exists.

javac detects that no new files were created by annotation processing, so it doesn't compile anything. According to https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#annotation-processing , javac only compiles "newly generated source files", so it doesn't compile the existing Foo_Factory.java.

I think the solution is, when maven-compiler-plugin detects that sources have changed it and it needs to re-compile, it should delete target/generated-sources/annotations as well as target/classes before compiling.


No further details from MCOMPILER-532

jira-importer avatar Apr 01 '23 09:04 jira-importer