What does a custom plugin need to do in order to access project properties?

The following code generates an error on the second reference to the project property ‘SpringVersion’.

plugins {

id “io.spring.dependency-management” version “0.2.1.RELEASE”

}

ext.SpringVersion=‘3.2.3.RELEASE’

dependencies {

compile(group: ‘org.springframework’, name: ‘spring-aop’, version: “$SpringVersion”)

}

dependencyManagement {

dependencies {

dependencySet(group: ‘org.springframework’, version: “$SpringVersion”) {

entry ‘spring-beans’

entry ‘spring-core’

}

}

}

The property can be successfully referenced in Gradle’s DependencyHandler, but it cannot be referenced by the plugin. It generates the following error.

No such property: $SpringVersion for class: io.spring.gradle.dependencymanagement.DependenciesHandler

What needs to be done in a custom plugin to reference project properties?

Not sure what the problem is. Some things to try:

  • Double-check that the version string really has double quotes (error message reads as if it had single quotes, in which case string interpolation isn’t supported) * Use ‘ext.springVersion’ (properties typically start with a lower-case letter, and names starting with an upper-case letter are sometimes considered a class name by Groovy) * Use ‘version: springVersion’ (no need for String interpolation here)