[java] Could not find method compile() for arguments Gradle

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?

This question is related to java groovy gradle

The answer is


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:

apply plugin:'java'

Hope Below steps will help

Add the dependency to your project-level build.gradle:

classpath 'com.google.gms:google-services:3.0.0'

Add the plugin to your app-level build.gradle:

apply plugin: 'com.google.gms.google-services'

app-level build.gradle:

dependencies {
        compile 'com.google.android.gms:play-services-auth:9.8.0'
}

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.


Just for the record: I accidentally enabled Offline work under Preferences -> Build,Execution,Deployment -> Gradle -> uncheck Offline Work, but the error message was misleading


Wrong gradle file. The right one is build.gradle in your 'app' folder.


In my case, all the compile statements has somehow arranged in a single line. separating them in individual lines has fixed the issue.


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 ...

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).

Gradle Version : 5.1.1


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to groovy

Jenkins pipeline how to change to another folder groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding Run bash command on jenkins pipeline Try-catch block in Jenkins pipeline script How to print a Groovy variable in Jenkins? Jenkins pipeline if else not working How to set and reference a variable in a Jenkinsfile Jenkins: Can comments be added to a Jenkinsfile? How to define and use function inside Jenkins Pipeline config? Jenkins: Cannot define variable in pipeline stage

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)