How to use an existing POJO as an extension object?


(Etienne Studer) #1

I have an existing POJO that I would like to use as an extension object in my custom plugin. Is there an elegant way to make this work without having to do any extra coding to map from the Gradle DSL to the extension object?

In the sample below, the existing POJO is called Configuration. I want to use it as an extension object. I cannot change the Configuration class since it is part of a 3-rd party library.

myExtension {
  foo {
    bar {
      alpha = 3;
    }
  beta = 'hello';
  }
}
class Configuration {
   Foo foo;
   String beta;
   void setFoo(Foo foo) {...}
   Foo getFoo() {...}
   void setBeta(String beta) {...}
   String getBeta() {...}
}
  class Foo {
   Bar bar;
   void setBar(Bar bar) {...}
   Bar getBar() {...}
}
  class Bar {
   int alpha;
   void setAlpha(int alpha) {...}
   int getAlpha() {...}
}

Regards, Etienne