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

[MCOMPILER-312] Maven annotation processor compiler error after changing the code

Open jira-importer opened this issue 8 years ago • 1 comments

Filipe Sousa opened MCOMPILER-312 and commented

Hi,

I've been using google dagger annotation processor with maven. Is this project (https://github.com/natros/dagger2-mcp-test) when I make a change I have to clean install otherwise I'm getting compiler errors.

Steps to reproduce:

first time compile, compiles ok

./mvnw clean compile

changing the code

sed -i -e 's@AuthService@//AuthService@' src/main/java/com/github/natros/mcp/Main.java

compile without clean and fail

./mvnw compile

clean compile and no errors

./mvnw clean compile

On a large project it does not makes sense to clean before compiling.

This is the error I'm getting:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/fsousa/Projects/tmp/dagger2-mcp-test/target/generated-sources/annotations/com/github/natros/mcp/DaggerMyComponent.java:[30,37] method create in class com.github.natros.mcp.Main_Factory cannot be applied to given types;
  required: javax.inject.Provider<com.github.natros.mcp.AuthService>,javax.inject.Provider<com.github.natros.mcp.UserService>
  found: dagger.internal.Factory<com.github.natros.mcp.UserService>
  reason: actual and formal argument lists differ in length
[ERROR] /Users/fsousa/Projects/tmp/dagger2-mcp-test/target/generated-sources/annotations/com/github/natros/mcp/Main_Factory.java:[26,12] constructor Main in class com.github.natros.mcp.Main cannot be applied to given types;
  required: com.github.natros.mcp.UserService
  found: com.github.natros.mcp.AuthService,com.github.natros.mcp.UserService
  reason: actual and formal argument lists differ in length
[INFO] 2 errors 

I asked this question to dagger creators who told me that this is a maven bug not a dagger one. https://github.com/google/dagger/issues/881#issuecomment-335854660


Affects: 3.7.0

Attachments:

Issue Links:

  • MCOMPILER-300 Maven compiler plugin 3.X.X recompiling generated sources and failing with compilation error ("Blocked")

jira-importer avatar Oct 12 '17 21:10 jira-importer

Børge N commented

We are also having issues with dagger and incremental compiles. (Possibly related to MCOMPILER-300.)

From what I can see, the problem is that the incremental build does not take generated sources into account at all, and there are two issues

  1. When computing sources, generated sources are correctly excluded (see [change|http://svn.apache.org/viewvc/maven/plugins/tags/maven-compiler-plugin-3.7.0/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java?r1=1726073&r2=1726074,] but when stale sources are computed, the generated sources are not excluded, so builds are triggered more often than necessary. This fix for this is straightforward.
  2. When computing the list of changed files, there is an incremental build helper to track the files in the output directory. These files are deleted before an incremental compile. Note that this also includes classes from generated sources. However, there are no incremental build helper for the generated sources, so the generated sources are not deleted. During compilation, javac sees that these files are already present, and therefore do not care to generated them again, and do not copy their respective class files to the output directory. After an incremental compilation, the output directory therefore do not include class files for generated sources, and further testing and/or compilation will break.

Attached is a crude patch for these two problems. The fix for the second item is rather ugly, because IncrementalBuildHelper only supports once directory, and the file lists (for the output directory and generated sources) need to be separated. But perhaps someone else can improve on this.

 

[^incremental_generate.patch]

jira-importer avatar Mar 14 '18 08:03 jira-importer