7

I have a desktop Java project using Dagger2 and building with Maven. I can't run compile and package sequentially. This works:

$ mvn clean
$ mvn compile

And this works, producing an executable jar that runs without error:

$ mvn clean
$ mvn package

But this fails:

$ mvn clean
$ mvn compile
$ mvn package

When package gets to the module that uses Dagger2, it outputs:

[INFO] Changes detected - recompiling the module!

The error from mvn -e package is:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:915)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more

The module has this dependency:

<dependency>
    <groupId>com.google.dagger</groupId>
    <artifactId>dagger</artifactId>
    <version>2.1</version>
    <scope>compile</scope>
</dependency>

The module uses compiler plugin version 3.3 like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.google.dagger</groupId>
            <artifactId>dagger-compiler</artifactId>
            <version>2.1</version>
        </dependency>
    </dependencies>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
    </configuration>
</plugin>

This is the only Dagger-related configuration. Why can't I run package after build?

Possibly related: I thought forceJavacCompilerUse was no longer needed, but without it, Dagger doesn't seem to run at all. I get an unknown symbol error on the generated component implementation (DaggerMyComponent).

Edit: This is the full output of mvn -e package, command prompt to command prompt:

kevin@aphrodite:~/Projects/IDEA/Dark Matter$ mvn -e package
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] parent
[INFO] weapon
[INFO] scripts
[INFO] assembly
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building weapon 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ weapon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ weapon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /home/kevin/Projects/IDEA/Dark Matter/weapon/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] parent ............................................ SUCCESS [0.001s]
[INFO] weapon ............................................ FAILURE [1.641s]
[INFO] scripts ........................................... SKIPPED
[INFO] assembly .......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.735s
[INFO] Finished at: Fri Mar 11 04:32:38 MST 2016
[INFO] Final Memory: 21M/173M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project weapon: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:915)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :weapon
kevin@aphrodite:~/Projects/IDEA/Dark Matter$ 

Edit 2: I noticed that when I run package by itself after clean, it says it's compiling 6 sources. That's how many hand-written classes are in the project. When I run compile before package, the latter says it's compiling 8 sources. It looks like when dagger-compiler runs on a clean project, it silently generates and compiles its sources. Then package sees the new sources and tries to compile them. The mystery is why it fails. Running compile twice in a row fails in the same way.

Edit 3: I tried this answer, specifying dagger.internal.codegen.ComponentProcessor as the -processor argument. Now the first time I run compile, I see the two passes where it compiles 6 files and then 8 files:

[INFO] --- maven-compiler-plugin:3.3:compile (process-annotations) @ weapon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /home/kevin/Projects/IDEA/Dark Matter/weapon/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ weapon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ weapon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /home/kevin/Projects/IDEA/Dark Matter/weapon/target/classes

This is expected, and this compile succeeds. But then if I run package, or compile again, it fails the same as before.

The sources Dagger produces are in /target/generated-sources/annotations. I think I need to tell Maven to do something with that path, but I don't know what. It makes sense that compile detects source changes when it is run twice in a row, though I don't know why that leads to failure. Maybe I need to run the annotation processing step conditionally, but I don't know how to do that or what the condition should be.

Community
  • 1
  • 1
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
  • Can you show the full error output cause based on the compile error message there must be more output... – khmarbaise Mar 11 '16 at 07:41
  • @khmarbaise That is the full output. The only thing I left out is the "For more information..." boilerplate at the end. – Kevin Krumwiede Mar 11 '16 at 08:36
  • It is not. There is output near the maven-compiler-plugin which shows the real problem and not only the part at the end... – khmarbaise Mar 11 '16 at 08:57
  • Try moving the dagger dependency out of your plugin setup, and mark it with compile ... that might alleviate some of your issues. – Roman Zenka Mar 11 '16 at 15:06
  • @RomanZenka That seems to prevent Dagger from running at all. I get `cannot find symbol` followed by a blank line instead of the name of the missing symbol. The location of the missing symbol `[3,35]` is an import statement referring to the Dagger component. – Kevin Krumwiede Mar 14 '16 at 19:07
  • have you tried running package goal with `mvn -X`, displaying debug output? – eis Mar 14 '16 at 19:22
  • @eis Yes. Do you think I should post all 600+ lines of output, or can you suggest what I should be looking for? – Kevin Krumwiede Mar 14 '16 at 20:06
  • not really, no. And it would be interesting to compare the differences between workin run and non-working one, but I'm not able to tell you a specific thing to look for in there. – eis Mar 14 '16 at 20:11

1 Answers1

3

I managed to reproduce your problem.

The key seems to be the maven-compiler-plugin:3.3

When I run with maven-compiler-plugin:3.1, the error does not manifest.

Roman Zenka
  • 3,514
  • 3
  • 31
  • 36
  • 1
    It didn't even occur to me that it could be a bug in the compiler plugin. It sounds closely related to [this issue](https://issues.apache.org/jira/browse/MCOMPILER-236). I confirmed that it's fixed in version 3.5.1, which was just released last month. – Kevin Krumwiede Mar 16 '16 at 06:24