Java 无法为参数 Gradle 找到方法 compile()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23796404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not find method compile() for arguments Gradle
提问by Ichbinjoe
Looked around for this solution for much too long now, and I'm not sure if I missed it or just misstyped something, but my Gradle script will not compile. I am migrating to Gradle, and am very new with it. I am very used to using Maven for dependency management, but Gradle seems best me for now. From running this snippet of code:
寻找这个解决方案的时间太长了,我不确定是我错过了它还是只是打错了一些东西,但我的 Gradle 脚本无法编译。我正在迁移到 Gradle,并且对它非常陌生。我非常习惯使用 Maven 进行依赖管理,但目前 Gradle 似乎最适合我。从运行这段代码:
dependencies {
compile group: 'org.bukkit', name: 'bukkit', version: '1.7.9-R0.1-SNAPSHOT'
compile('io.ibj:MattLib:1.1-SNAPSHOT') {
exclude group: 'de.bananaco'
exclude 'net.milkbowl:vault:1.2.27'
}
compile group: 'net.citizensnpcs', name: 'citizens', version: '2.0.12'
compile group: 'com.sk89q', name: 'worldedit', version: '5.6.1'
compile group: 'com.sk89q', name: 'worldguard', version: '5.9'
compile group: 'net.milkbowl', name: 'vault', version: '1.2.12'
compile fileTree(dir: 'libs', includes: ['*.jar'])
}
NOTE: I do have the java, maven, nexus, shadow, and rebel plugins applied.
注意:我确实应用了 java、maven、nexus、shadow 和 rebel 插件。
When I run my Gradle task, I encounter this error:
当我运行 Gradle 任务时,我遇到了这个错误:
Could not find method compile() for arguments [[io.ibj:MattLib:1.1-SNAPSHOT], build_1b5iofu9r9krp7o8mme0dqo9l$_run_closure2_closure8@66fb45e5] on root project 'project'
If I remove the "MattLib" dependency from my project and reinsert it as
如果我从我的项目中删除“MattLib”依赖项并将其重新插入为
compile 'io.ibj:MattLib:1.1-SNAPSHOT'
The script completes, but I have dependency issues. I read up here:
脚本完成,但我有依赖性问题。我在这里阅读:
dependencies {
compile("org.gradle.test.excludes:api:1.0") {
exclude module: 'shared'
}
}
(From Chapter 50 From the Gradle Manual, http://www.gradle.org/docs/current/userguide/dependency_management.html)
(来自 Gradle 手册的第 50 章,http://www.gradle.org/docs/current/userguide/dependency_management.html)
that what I have SHOULD work, but I am confused why it doesn't.
我所拥有的应该起作用,但我很困惑为什么它不起作用。
gradle --version output:
gradle --version 输出:
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy: 2.2.0
JVM: 1.8.0_05 (Oracle Corporation 25.5-b02)
OS: Windows 7 6.1 amd64
Any thoughts?
有什么想法吗?
采纳答案by Radim
It should be exclude module: 'net.milkbowl:vault:1.2.27'
(add module:
) as explained in documentation for DependencyHandler
linked from http://www.gradle.org/docs/current/javadoc/org/gradle/api/Project.html#dependencies(groovy.lang.Closure)because ModuleDependency.exclude(java.util.Map)
method is used.
它应该是exclude module: 'net.milkbowl:vault:1.2.27'
(add module:
),如http://www.gradle.org/docs/current/javadoc/org/gradle/api/Project.html#dependencies(groovy.lang.Closure)DependencyHandler
链接的文档中所述,因为方法是用过的。ModuleDependency.exclude(java.util.Map)
回答by Rene Groeschke
compile
is a configuration
that is usually introduced by a plugin (most likely the java plugin) Have a look at the gradle userguide for details about configurations. For now adding the java plugin on top of your build script should do the trick:
compile
是一个configuration
通常由插件(最有可能是java插件)引入的。有关配置的详细信息,请查看gradle用户指南。现在在你的构建脚本之上添加 java 插件应该可以解决问题:
apply plugin:'java'
回答by RussellStewart
Make sure that you are editing the correct build.gradle
file. I received this error when editing android/build.gradle
rather than android/app/build.gradle
.
确保您正在编辑正确的build.gradle
文件。我在编辑android/build.gradle
而不是android/app/build.gradle
.
回答by Priyanshu Singh
Hope Below steps will help
希望以下步骤会有所帮助
Add the dependency to your project-levelbuild.gradle:
将依赖项添加到您的项目级build.gradle:
classpath 'com.google.gms:google-services:3.0.0'
Add the plugin to your app-levelbuild.gradle:
将插件添加到您的应用程序级build.gradle:
apply plugin: 'com.google.gms.google-services'
app-levelbuild.gradle:
应用级build.gradle:
dependencies {
compile 'com.google.android.gms:play-services-auth:9.8.0'
}
回答by Rohit Mandiwal
In my case, all the compile
statements has somehow arranged in a single line. separating them in individual lines has fixed the issue.
就我而言,所有compile
语句都以某种方式排列在一行中。将它们分开在单独的行中解决了这个问题。
回答by letanthang
Wrong gradle file. The right one is build.gradle in your 'app' folder.
错误的 gradle 文件。正确的是“app”文件夹中的 build.gradle 。
回答by dr0i
In my case I had to remove some files that were created by gradle at some point in my study to make things work. So, cleaning up after messing up and then it ran fine ...
就我而言,我不得不删除一些由 gradle 在我的研究中的某个时刻创建的文件,以使事情正常进行。所以,搞砸后清理,然后运行良好......
If you experienced this issue in a git project, do git status
and remove the unrevisioned files. (For me elasticsearch
had a problem with plugins/analysis-icu
).
如果您在 git 项目中遇到此问题,请执行git status
并删除未修订的文件。(对我来说elasticsearch
有问题plugins/analysis-icu
)。
Gradle Version
: 5.1.1
Gradle Version
: 5.1.1
回答by longi
Just for the record: I accidentally enabled Offline workunder Preferences -> Build,Execution,Deployment -> Gradle -> uncheck Offline Work, but the error message was misleading
仅作记录:我不小心在Preferences -> Build,Execution,Deployment -> Gradle -> 取消选中 Offline Work下启用了Offline work,但错误消息具有误导性