maven - 排除 AnnotationProcessorPaths 中的依赖项
问题描述
我有以下构建配置:
父 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>
其中一个子项目包含以下内容:
<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>
当我运行此配置时,我不断收到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)
...
当我检查这些工件的依赖关系时,com.google.auto.value:auto-value:1.6.5
(在检查父母之后)依赖于com.squareup:javapoet:1.9.0
,并且com.google.dagger:dagger-compiler:2.24
依赖于com.squareup:javapoet:1.11.1
.
当我检查in的签名ClassName::withoutAnnotation
com:squareup:javapoet:1.11.1
时public ClassName withoutAnnotations()
。
in的签名ClassName::withoutAnnotation
com:squareup:javapoet:1.9.0
是public TypeName withoutAnnotations()
。
因此,确实存在冲突。
如果它是正常的依赖项,我会知道使用<exclusions>
标签,但在这种情况下,如果我添加这样的标签,我会遇到以下问题:Cannot find 'exclusions' in class org.apache.maven.plugin.compiler.DependencyCoordinate
.
那么我该如何解决这种冲突annotationProcessorPaths
呢?
解决方案
您可以通过直接将其添加为注释处理器路径来手动覆盖 JavaPoet 的版本:
<path>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
<version>1.11.1</version>
</path>
(我们为同样的问题做了同样的事情。)
此外,我已经启动了更新 AutoValue 的过程,以避免(目前)这个问题。到目前为止,这只是这个 commit。
(另外,一个技术说明:冲突并不像最初看起来那么糟糕:withoutAnnotations
返回的版本TypeName
存在于两个版本的字节码中。这是因为,在 1.10.0+ 中,编译器会自动在除了返回的“真实”版本ClassName
。我立即完全理解了这一点,根本没有提交错误的错误报告;))
推荐阅读
- wolfram-mathematica - 将图例添加到使用 Show 函数创建的多重图中
- jquery - 为什么 jquery datatable 在显示数据详细信息后会抑制顶线和底线?
- r - R中的复杂交叉表
- git - 在 Heroku 应用程序上 pip 安装私有 git 存储库的正确/安全方法是什么?
- c++ - 在这种情况下如何管理继承?
- javascript - Javascript 应用于不同的反应页面
- wordpress - 如何在 Wordpres 中编辑 custom.css 文件
- spring-boot - 春季启动普罗米修斯指标中无法解释的“根”uri
- python-datetime - 树莓 GPIO,时间触发
- python - 为在 namecheap 共享托管计划上托管的网站安装 mysqlclient 时出现问题