fralbo
fralbo

Reputation: 2664

Error:(24, 0) Could not find method annotationProcessor() for arguments [com.google.dagger:dagger-compiler:2.10]

I try to build a module:api on Android Studio 3, gradle 4.1, Android Studio plugin 3.0.0, using Dagger 2

So my build.gradle is:

apply plugin: 'java-library'

repositories {
    jcenter()
    google()
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':api_shared')

    // Guava
    implementation group: 'com.google.guava', name: 'guava', version: '23.0'

    // Dagger 2
    compile 'com.google.dagger:dagger:2.10'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

And I get the following error.

Error:(24, 0) Could not find method annotationProcessor() for arguments [com.google.dagger:dagger-compiler:2.10] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
<a href="openFile:D:\Users\me\Workspace\Sample3\api\build.gradle">Open File</a>

I saw similar errors for guys using old plugin version but here, I don't understand why I get this error. Any idea?

Upvotes: 2

Views: 3545

Answers (2)

daniel.keresztes
daniel.keresztes

Reputation: 885

You can't use the annotationProcessor in java-library, you need to use the apt but for that you need to add the following to the build.gradle:

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

apply plugin: 'java-library'
apply plugin: "net.ltgt.apt"

After that you can use:

apt 'com.google.dagger:dagger-compiler:2.10'

Upvotes: 2

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363825

You need the Android Gradle plugin (version 2.2 or newer) to use the annotationProcessor DSL.

You are using apply plugin: 'java-library' not the Android Plugin.

Upvotes: -1

Related Questions