Skip to content

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

Description

@jira-importer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:minorMinor loss of function, or other problem where easy workaround is present

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions