Ideas for how to implement a dependencies{}-like DSL

The syntax I’d really like to leverage is that of the dependencies {} block. Something like:

        persistenceUnits {
            abc project( ":subProject1" )

            def project( ":subProject2" )
            def 'com.acme:our-entities:the.version`

The idea is that these define JPA persistence-units and we want to collect the dependencies per unit.

I’ve looked at DependencyHandler but I am not sure how something like implementation 'a:b:c' gets mapped to the DependencyHandler#add call (assuming that is what it gets routed to).

Any ideas on how to model this?

Thanks in advance.

You’d do something like

class MyExtension {
   private final PersistenceUnits persistenceUnits
   public MyExtension(Project project) { 
      this.persistenceUnits = new PersistenceUnits(project)
   public persistenceUnits(Closure closure) {
   // getter for third parties to hook into events 
   public PersistenceUnits getPersistenceUnits() {
      returh this.persistenceUnits
class PersistenceUnits {
   private final NamedDomainObjectCollection<Foo> foos
   public PersistenceUnits(Project project) { 
      this.foos = project.objectFactory.namedDomainObjectSet(Foo.class)
   def methodMissing(String name, args) {
      // name will contain abc, args will contain the project
   // getter for third parties to hook into events 
   public NamedDomainObjectCollection<Foo> getFoos() {
      return this.foos

Thanks again @Lance !

Of course… I keep forgetting about the Groovy missing-method magic.

Quick question… do solutions such as this work “properly” with Kotlin scripts in terms of auto-completion, etc?