MissingPropertyException thrown for extended properties used in build/dependencies section of build.gradle

Here’s a test case build.gradle file.

https://gist.github.com/samrocketman/06d4cfc37e1e1c453db5

If you uncomment line 9 then gradle throws a MissingPropertyException. I’ve included a wrapper section so that it is easy to test against the latest stable gradle 2.2.1.

‘’’ gradle wrapper ./gradlew assemble ‘’’

Then after uncommenting line 9 in the test case.

‘’’ ./gradlew assemble --stacktrace ‘’’

The reason for this is because the ‘buildscript {…}’ block is evaluated before your project so that property does not yet exist. If you want to use properties within a ‘buildscript {…}’ block you will have to specify the properties on the CLI using ‘-Dprop=value’ or in a gradle.properties file.

Then I would at the very least consider it a documentation bug. Because the extended property documentation makes no mention of the exception you just mentioned. It claims that you set the property and can just use it where-ever. It took me a few weeks to figure out it was this strange case as you mention with some help in the IRC channel towards the end of my debugging.

For reference, I’m using this way to test against multiple versions of groovy in my project https://github.com/samrocketman/jervis/blob/master/build.gradle

hffg

h