为什么我的gradle构建失败? (找不到方法apt())

时间:2017-03-07 06:12:10

标签: java intellij-idea gradle groovy

在我尝试使用带有gradle的apt或其他插件作为我正在编写的注释处理器之前,一切都运行良好。我已经能够手动构建和运行所有内容(使用/不使用gradle),但是一旦引入插件就会出现问题。这是我的剧本:

这是我的buildscript:

buildscript {

    evaluationDependsOn('compiler')
    evaluationDependsOn('core')

    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        flatDir { dirs './make' }
    }

    dependencies {
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.9"
        classpath ':core:0.1'
        apt ':compiler:0.1'
    }
}

plugins {
    id 'java'
    id 'idea'
    id "net.ltgt.apt" version "0.9"
}

group 'bundle'
version '0.1-SNAPSHOT'

我正在使用gradle-apt-plugin。我也尝试使用Palantir's annotation processing plugin并且引发了确切的错误,这使我相信插件和我的配置和/或版本的内容没有任何问题。

本地gradle版本:2.1 和 Gradle包装:3.4.1

Intellij中启用了注释处理。我还检查过我使用了远程插件存储库的正确URL。我试过回滚gradlew版本。

Intellij警告我“发现了未编制索引的远程maven存储库”,但根据想法论坛it's a bug but won't affect a build.除此之外,我不知道是什么导致这种失败。

这是输出:

FAILURE: Build failed with an exception.

* Where:
Build file '/home/$USER/IdeaProjects/$PROJECT/build.gradle' line: 14

* What went wrong:
A problem occurred evaluating root project 'Dynamic-MVP'.
> Could not find method apt() for arguments [:compiler:0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

1 个答案:

答案 0 :(得分:3)

您正在尝试将其添加到buildscript依赖项中,这是不正确的。 Buildscript依赖项只能是classpath。您需要将其添加到项目依赖项中:

dependencies {
    apt ':compiler:0.1'
}

buildscript关闭。