Dagger 2.0 - AppEngine - gradle配置 [英] Dagger 2.0 - AppEngine - gradle configuration

查看:181
本文介绍了Dagger 2.0 - AppEngine - gradle配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在AppEngine项目( NOT Android之一)中从Dagger 1.2.2移到Dagger 2.0.1。

I am trying to move from Dagger 1.2.2 to Dagger 2.0.1 in AppEngine project (NOT Android one).

Dagger 1.2.2简单:

With Dagger 1.2.2 simple:

compile 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.dagger:dagger:1.2.2'

完成了这个诀窍。

使用Dagger 2.0.1:

With Dagger 2.0.1:

compile 'com.google.dagger:dagger-compiler:2.0.1'
compile 'com.google.dagger:dagger:2.0.1'

不起作用(源代码生成,但与build / classes / main / .. package ../中的* .class文件混淆)。

does not work (source is generated but mixed up with *.class files in build/classes/main/..package../).

推荐答案

我找到了解决方案。

https://github.com/tbroyer/gradle-apt-plugin

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
  }
}

apply plugin: "net.ltgt.apt"

dependecies {
  apt 'com.google.dagger:dagger-compiler:2.0.1'
  compile 'com.google.dagger:dagger:2.0.1'
}

另外,如果您使用Intellij,推荐:

Additionally if you are using Intellij a following configuration is recommended:


然而,在IntelliJ IDEA中使用Gradle集成而不是想法任务时,您必须手动启用注释
处理:在设置...→构建,执行,部署→编译器→
注释处理器,选中启用注解处理并从项目类路径中获取
处理器。为了模仿Gradle行为和
生成的文件行为,您可以配置生成和测试
sources目录以生成/ generated / source / apt / main和
build / generated / source / apt /测试,并选择存储
生成的源相对于:模块内容根。

When using the Gradle integration in IntelliJ IDEA however, rather than the idea task, you'll have to manually enable annotation processing: in Settings… → Build, Execution, Deployment → Compiler → Annotation Processors, check Enable annotation processing and Obtain processors from project classpath. To mimic the Gradle behavior and generated files behavior, you can configure the production and test sources directories to build/generated/source/apt/main and build/generated/source/apt/test respectively and choose to Store generated sources relative to: Module content root.

我也必须删除排除从整个构建目录和标记生成/源/ apt /主目录作为源。

I've also had to remove Exclude from whole build directory and mark generated/source/apt/main directory as source.

这篇关于Dagger 2.0 - AppEngine - gradle配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆