Maven: compile OK, package OK, compile + package

I have a working Java project using Dagger2 and building with Maven. I cannot run compile and package sequentially. It works:

 $ mvn clean $ mvn compile 

And this works by creating an executable jar that works without errors:

 $ mvn clean $ mvn package 

But this fails:

 $ mvn clean $ mvn compile $ mvn package 

When package goes into a module that uses Dagger2, it produces:

 [INFO] Changes detected - recompiling the module! 

Error mvn -e package :

 [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 the compiler version 3.3 plugin as follows:

 <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 ?

Perhaps this is connected: I thought forceJavacCompilerUse no longer needed, but without it the Dagger does not work at all. I get an unknown character error in the implementation of the generated component ( DaggerMyComponent ).

Edit: This is the full output of mvn -e package , the command line on the command line:

 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$ 

Change 2 . I noticed that when I run package myself after clean , it says that it compiles 6 sources. This is the number of handwritten classes in the project. When I run compile before package , the latter says that it compiles 8 sources. It seems that when the dagger-compiler works in a clean project, it silently generates and compiles its sources. Then package sees new sources and tries to compile them. A mystery is why it fails. Running compile twice in a line does not execute in the same way.

Edit 3: I tried this answer by specifying dagger.internal.codegen.ComponentProcessor as the argument to -processor . The first time I start compilation, I see 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 compile is expected to succeed. But if I run package or compile again, it will not be the same as before.

Dagger sources are produced in /target/generated-sources/annotations . I think I need to tell Maven to do something with this path, but I don't know what. It makes sense that compile detects source changes when it runs twice in a row, although I don't know why this leads to an error. Perhaps I need to complete the annotation processing step conditionally, but I don’t know how to do it or what the condition should be.

+7
maven dagger-2
source share
1 answer

I was able to reproduce your problem.

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

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

+3
source share

All Articles