I have the following build configuration:
Parent POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.6.5</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
One of the child project contains the following:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.24</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
When I run this configuration, I keep getting an org.apache.maven.lifecycle.LifecycleExecutionException
:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project imgn: Fatal error compiling
...
Caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling
...
Caused by: org.codehaus.plexus.compiler.CompilerException: java.lang.NoSuchMethodError: com.squareup.javapoet.ClassName.withoutAnnotations()Lcom/squareup/javapoet/ClassName;
...
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: com.squareup.javapoet.ClassName.withoutAnnotations()Lcom/squareup/javapoet/ClassName;
...
Caused by: java.lang.NoSuchMethodError: com.squareup.javapoet.ClassName.withoutAnnotations()Lcom/squareup/javapoet/ClassName;
at dagger.internal.codegen.langmodel.DaggerElements.getTypeElement(DaggerElements.java:105)
at dagger.internal.codegen.InjectBindingRegistryImpl$BindingsCollection.shouldGenerateBinding(InjectBindingRegistryImpl.java:134)
...
When I check the dependencies of those artifacts, com.google.auto.value:auto-value:1.6.5
(after checking parents) depends on com.squareup:javapoet:1.9.0
, and com.google.dagger:dagger-compiler:2.24
depends on com.squareup:javapoet:1.11.1
.
When I check the signature of ClassName::withoutAnnotation
in com:squareup:javapoet:1.11.1
is public ClassName withoutAnnotations()
.
The signature of ClassName::withoutAnnotation
in com:squareup:javapoet:1.9.0
is public TypeName withoutAnnotations()
.
So indeed, there is a clash.
If it were normal dependencies, I'd know to use the <exclusions>
tag, but in this case, if I add such tag, I get the following issue: Cannot find 'exclusions' in class org.apache.maven.plugin.compiler.DependencyCoordinate
.
So how do I fix such clash in annotationProcessorPaths
?
As of version 3.11.0 of the maven-compiler-plugin, you can exclude transitive dependencies for <annotationProcessorPaths>
as well:
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.6.5</version>
<exclusions>
<exclusion>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
</exclusion>
</exclusions>
</path>
</annotationProcessorPaths>
See also: MCOMPILER-395