Could not find method compile() for arguments Gradle

Ichbinjoe picture Ichbinjoe · May 22, 2014 · Viewed 172k times · Source

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:

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.

When I run my Gradle task, I encounter this error:

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

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 )

that what I have SHOULD work, but I am confused why it doesn't.

gradle --version output:

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?

Answer

RussellStewart picture RussellStewart · Oct 28, 2015

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.