简体   繁体   中英

Can't add Dagger 2 dependency to java module

I'm trying to separate my android application into several modules. For instance I want to have 2 extra modules - Core and ViewModels. Both of them are pure java modules. However I'm having troubles when adding Dagger 2 dependencies to those java modules. Here's the build gradle file of one of the modules

apply plugin: 'java-library'


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.dagger:dagger:2.15'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.15'
    implementation 'org.greenrobot:eventbus:3.1.1'
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

However, when I sync the gradle I get the following error

Could not find method classpath() for arguments [com.neenbedankt.gradle.plugins:android-apt:1.8] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File

Any ideas why is this happening?

I've resolved the issue. Here's what my final build.gradle of the custom module looks like

plugins {
    id "net.ltgt.apt" version "0.15"
}
apply plugin: 'java-library'



dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.dagger:dagger:2.15'
    apt 'com.google.dagger:dagger-compiler:2.13'
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

Dagger 2 successfuly generated necessary code and app worked like magic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM