Dagger 2.0 - AppEngine setup - gradle

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

With Dagger 1.2.2, it’s easy:

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

did the trick.

With Dagger 2.0.1:

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

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

+2
source share
2 answers

I have found a solution.

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'
}

In addition, if you are using Intellij, the following configuration is recommended:

Gradle IntelliJ IDEA, , , : ... → , , → → , . Gradle , ///apt/main build/generated/source/apt/test Store : .

/source/apt/main .

0

net.ltgt.apt (, , ).

apply plugin: 'java'
apply plugin: 'idea'

def generatedMain = new File(buildDir, "generated/main")

compileJava {
    doFirst {
        generatedMain.mkdirs()
    }
    options.compilerArgs += ['-s', generatedMain]
}
idea.module.sourceDirs += generatedMain

dependencies {
    compileOnly 'com.google.dagger:dagger-compiler:2.8'
    compile 'com.google.dagger:dagger:2.8'
}
+1

All Articles