【问题标题】:Annotation exception with Dagger 2Dagger 2 的注释异常
【发布时间】:2015-09-26 03:29:57
【问题描述】:

我正在尝试将 Dagger 2 作为我的依赖注入框架与 Vaadin 集成。但是,看起来可能与 Vaadin 和 Dagger 的 Guava 依赖项中包含的 Guava 版本存在冲突。我已将 IntelliJ 中的构建命令范围缩小到 vaadin:compile,结果如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project vaadin: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] 
[ERROR] 
[ERROR] An annotation processor threw an uncaught exception.
[ERROR] Consult the following stack trace for details.
[ERROR] java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.filterKeys(Lcom/google/common/collect/SetMultimap;Lcom/google/common/base/Predicate;)Lcom/google/common/collect/SetMultimap;

我尝试将构建路径中 Dagger 编译器的范围更改为 provided,但仍然遇到问题。

有没有办法解决 Vaadin 和 Dagger 之间的编译时间问题?

【问题讨论】:

  • 请尝试排除低版本旧番石榴依赖。新版本几乎总是向后兼容。
  • vaadin-client 已经设置为“provided”,所以我不确定如何在不破坏 Vaadin 的情况下进一步排除它。
  • Here 写的是如何完全排除依赖关系。您可以使用mvn dependency:tree 查看完整的依赖树

标签: java web dependency-injection vaadin dagger-2


【解决方案1】:

因此,当您是使用 Dagger 的移动开发人员并尝试切换到使用 Maven 进行 Web 应用程序开发时,可能会发生这种情况。我无法理解/阅读使用 Dagger 2 和 Maven 的说明:

在 Maven 项目中,可以在依赖项中包含运行时 pom.xml 的部分,以及 dagger-compiler 工件作为 编译器插件的依赖:

使用 Gradle,我会将导入文件放在 build.gradle 中的相同位置。我终于意识到我需要将编译器添加到 pom.xml 的单独部分中,用于 maven 插件编译器:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
        <dependencies>
            <dependency>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-compiler-javac</artifactId>
                <version>1.8.6</version>
            </dependency>
            **<dependency>
                <groupId>com.google.dagger</groupId>
                <artifactId>dagger-compiler</artifactId>
                <version>2.0</version>
                <optional>true</optional>
            </dependency>**
        </dependencies>
    </plugin>

经验教训。

【讨论】:

    猜你喜欢
    • 2013-01-09
    • 2012-04-23
    • 2015-10-03
    • 1970-01-01
    • 2019-11-28
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多