Property not found in buildScript dependency

I have a very basic build script:

apply plugin: 'groovy'
apply plugin: 'application'
apply plugin: 'cobertura'
  // Versions
ext {
    coberturaVersion = '1.1.2'
}
  repositories {
    mavenCentral()
}
  buildscript {
    repositories {
        mavenCentral()
    }
      dependencies {
        classpath group: 'net.saliman', name: 'gradle-cobertura-plugin', version: coberturaVersion
    }
}

Executing

gradle -q

will result in an error ‘No such property: coberturaVersion for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler’

Using a property (defined in ext block) in the

dependencies

block like

dependencies {
   compile group: 'org.codehaus.groovy:', name: 'groovy-all', version: groovyVersion
}

works perfectly fine. My expectation was, that referencing a property will work everywhere. Is there something that I missed in the documentation about this behavior, or is this a bug?

It is the expected behavior. The ‘buildscript’ block is very special and effectively its own build script that gets evaluated before the rest of the build script can even be compiled. Therefore the ‘buildscript’ block cannot see the rest of the build script, but the rest of the build script can see the ‘buildscript’ block.

Thank you for clarifying this. Perhaps it’s worth to mention this in the documentation. I understand the technical restrictions, but since the block looks like every other dependencies block, everybody would expect similar behavior. Just my 2 cents.