Search code examples
gradleandroid-gradle-plugingroovy-console

GroovyConsole running build.gradle


GradleWare's book - Building and Testing with Gradle - states the following in section 1.1: "Every Gradle build file is an executable Groovy script."

However, when I run a build.gradle file in GroovyConsole, it gives me this error:

groovy.lang.MissingMethodException: No signature of method: build.apply() is applicable for argument types: (java.util.LinkedHashMap) values: [[plugin:android-library]] Possible solutions: any(), any(groovy.lang.Closure), every(), every(groovy.lang.Closure), split(groovy.lang.Closure) at build.run(build.gradle:1)

It refers to line 1:

apply plugin: 'android-library'

In the build script:

apply plugin: 'android-library'

dependencies {
  compile 'com.android.support:support-v4:18.0.+'
}

android {
  compileSdkVersion 14
  buildToolsVersion '17.0.0'

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = ['src']
      res.srcDirs = ['res']
    }
  }
}

So can you please clarify whether the book's statement is correct or wrong??

Thank you, Igor Ganapolsky


Solution

  • The statement isn't to be taken literally. A Gradle script cannot be run with plain Groovy, just like a Javascript snippet on a web page cannot be run in a plain JavaScript engine outside the browser.