I am trying to create an extension with dynamic object with getProperty(name), but it doesn’t work for me. My intent is to use a self-explaining properties for string values/constants, so they are not hard-coded and their usage is consistent across all build scripts.
class DynamicPropertyObject{
def storage
DynamicPropertyObject() {
storage = [:]
}
DynamicPropertyObject(initialStorage) {
storage = initialStorage;
}
void setProperty(String name, value) {
storage[name] = value
}
def getProperty(String name) {
storage[name]
}
}
class MsBuildPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.extensions.create("msBuild", DynamicPropertyObject,
[ "arch": new DynamicPropertyObject(['x86' : 'win32', 'x64':'x64']),
"config": new DynamicPropertyObject(['debug' : 'Debug', 'release':'Release']),
"target": new DynamicPropertyObject(['build' : 'build', 'clean':'clean']) ]);
}
}
apply plugin: MsBuildPlugin
ext.testMe = new DynamicPropertyObject(
[ "arch": new DynamicPropertyObject(['x86' : 'win32', 'x64':'x64']),
"config": new DynamicPropertyObject(['debug' : 'Debug', 'release':'Release']),
"target": new DynamicPropertyObject(['build' : 'build', 'clean':'clean']) ]);
println "testMe.arch.x86:" + testMe.arch.x86 //works fine
println "msBuild.arch.x86:" + msBuild.arch.x86
// doesn't work
It fails with following error.
* Where:
Build file 'D:\Projects\gradle\dynaProp\build.gradle' line: 44
* What went wrong:
A problem occurred evaluating root project 'dynaProp'.
> Could not find property 'arch' on DynamicPropertyObject_Decorated@163b254.
Is there some restriction so Extension must be just POGO/POJO? If yes, some hint how can I achieve that effect w/o creation of special class for each node in hierarchy is welcome.
Thanks, Bronislav