小编R.T*_*ier的帖子

在没有 Android 的情况下使用 Dagger2

我想在 Gradle 项目中使用 Dagger2 和 MVP,但不使用 Android,而是使用本机 Java。但我无法构建我的项目,DaggerAppComponent 类永远不会生成。该类由 Dagger lib 在编译时自动生成。

构建.gradle:

plugins {
    id "net.ltgt.apt" version "0.11"
}
apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

compileJava {
    options.annotationProcessorPath = configurations.apt
}

configurations {
    apt
}


dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile "com.google.dagger:dagger:2.11"
    apt     "com.google.dagger:dagger-compiler:2.11"
    apt     "com.google.dagger:dagger-producers:2.11"


    compileOnly "com.google.auto.factory:auto-factory:1.0-beta3"
    apt         "com.google.auto.factory:auto-factory:1.0-beta3"

    compileOnly "org.immutables:value:2.2.10:annotations"
    apt         "org.immutables:value:2.2.10"


    provided 'javax.annotation:jsr250-api:1.0'
    compile 'org.glassfish:javax.annotation:10.0-b28'

}
Run Code Online (Sandbox Code Playgroud)

主程序.java

public class Main {

private static AppComponent appComponent; …
Run Code Online (Sandbox Code Playgroud)

java dependency-injection intellij-idea dagger-2

6
推荐指数
1
解决办法
1313
查看次数