java - Eclipse 启用注释处理导致错误

标签 java eclipse gwt gradle

我有 Eclipse Luna 和一个标准的 GWT Web 应用程序项目。我尝试启用注释处理,但 make Dagger2在职的。这是我的项目特定配置:

enter image description here

enter image description here

点击“应用”后,Eclipse 显示以下错误:

enter image description here

如何解决此错误?

编辑:我创建了一个演示项目来演示该问题:https://github.com/confile/GWT-Dagger2-Demo

我查看了 dagger2 编译器的 pom.xml 并添加了更多依赖项,但仍然没有进展。这是我所做的:

enter image description here

编辑:我尝试使用 dagger2 编译器 jar 及其依赖项 here :

当我进行 GWT 编译时,出现以下错误:

Compiling module test.GWTT
   Tracing compile failure path for type 'test.client.test2.Dagger_MyWidgetGinjector'
      [ERROR] Errors in 'file:/Users/mg/Documents/Eclipse/Eclipse-4.4/GWTT/.apt_generated/test/client/test2/Dagger_MyWidgetGinjector.java'
         [ERROR] Line 9: No source code is available for type javax.inject.Provider<T>; did you forget to inherit a required module?
   Tracing compile failure path for type 'test.client.test2.MyWidgetClientModule$$ProvideSomeServiceFactory'
      [ERROR] Errors in 'file:/Users/mg/Documents/Eclipse/Eclipse-4.4/GWTT/.apt_generated/test/client/test2/MyWidgetClientModule$$ProvideSomeServiceFactory.java'
         [ERROR] Line 7: No source code is available for type dagger.Factory<T>; did you forget to inherit a required module?
   [ERROR] Aborting compile due to errors in some input files

我的 Java 构建路径上有以下库:

enter image description here

编辑 Gradle:我还尝试在 Eclipse 中使用 gradle 激活注释处理。这是我的 gradle build.gradle 文件:

apply plugin: 'apt'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'gwt'
apply plugin: 'jetty'

sourceCompatibility = 1.7
version = '1.0'

eclipse {
    classpath {
       downloadSources=true
       downloadJavadoc=true
    }
}

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'      
        classpath 'com.jimdo.gradle:gradle-apt-plugin:0.5-SNAPSHOT'
    }
}


repositories {
    mavenCentral()
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/repositories/snapshots/"
    }
}

dependencies {
    apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT:jar-with-dependencies'

    compile 'com.google.guava:guava:18.0'
    compile 'com.google.guava:guava-gwt:18.0'
    compile 'javax.inject:javax.inject:1'   
    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
}

gwt {
    gwtVersion='2.7.0'
    logLevel = 'INFO'
    minHeapSize = "512M";
    maxHeapSize = "1024M";


    compiler {
        strict = true;
    }

    modules 'test.GWTT'     
}

tasks.withType(de.richsource.gradle.plugins.gwt.AbstractGwtActionTask) {
    args '-XjsInteropMode', 'JS'
}

在“gradle build”之后我得到:

/Users/mg/Documents/Grails/GGTS3.6.2/TestGradle2/src/main/java/test/client/GWTT.java:16: error: cannot find symbol
         MyWidgetGinjector injector = Dagger_MyWidgetGinjector.create();
                                      ^
  symbol:   variable Dagger_MyWidgetGinjector

我可以看到Dagger_MyWidgetGinjector.java已在build/source/apt/test/client/test2/中创建。我仍然需要弄清楚如何添加新生成的源,以便 Eclipse 使用刷新依赖项找到它?

最佳答案

Dagger 2 尚未遮蔽其依赖项,因此您必须将所有 dagger-compiler 依赖项添加到工厂路径中。

编辑:有一个包含所有依赖项的 jar-with-dependencies 风格,让像您这样不使用所谓的托管依赖项的用户更容易使用,但代价是在使用具有相同传递依赖项的其他注释处理器时可能会发生冲突。理想情况下,dagger-compiler 应该隐藏其依赖项以生成无冲突的 uber-jar;我相信这最终会实现。

关于java - Eclipse 启用注释处理导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28309971/

相关文章:

java - JAVA程序根据出生日期和当前日期计算人的年龄

java - 如何在 JFace LabelProviders 中处理 Windows shell 图标?

java - 嵌套在泛型中的类的泛型使用

java - 即使我安装了 Java 8,Yosemite 也仅识别 1.6.0.jdk。我无法修改 java_home

java - Spring JPA 的 "refreshing"实体后未反射(reflect)更改

java - 如何使用 eclipse 将图像添加到 java 项目中?

java - 保存文件的相对路径

javascript - 如何将 Google Analytics 集成到 GWT 应用程序中?

java - 如何在显示下一个 View 之前清除 RootPanel

gwt - 在 GWT 中处理浏览器刷新