一切正常,直到我尝试将 apt 或其他插件与 gradle 一起用于我正在编写的注释处理器。我已经能够手动构建和运行所有内容(有/没有 gradle),但是一旦我引入插件就会遇到问题。这是我的脚本:
这是我的构建脚本:
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.
最佳答案
您正试图将其添加到构建脚本依赖项中,这是不正确的。 Buildscript 依赖项只能是 classpath
。您更需要将它添加到您的项目依赖项中:
dependencies {
apt ':compiler:0.1'
}
在 buildscript
闭包之外。
关于java - 为什么我的 gradle 构建失败? (找不到方法 apt()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42641396/