Is there a public API for creating an instance of DomainObjectCollection?

I’m looking for a public API to create an instance of org.gradle.api.DomainObjectCollection. I am aware that I can create an instance of org.gradle.api.NamedDomainObjectContainer via Project.container() but my objects are not named. So far I only found that it’s very easy to instantiate org.gradle.api.internal.DefaultDomainObjectSet as it has a constructor taking just the type but it’s clearly an internal API given the package it lives under.

The reason I ask is because I would like to use its “live collection” behaviour to support lazy configuration in my custom plugin.

An API for this was added in 5.5:

https://docs.gradle.org/current/javadoc/org/gradle/api/model/ObjectFactory.html#domainObjectSet-java.lang.Class-

There are also named and polymorphic factory methods.

2 Likes

Thanks, @sterling, that’s useful to know cause the only thing I was able to find before was org.gradle.util.WrapUtil.toDomainObjectSet() which doesn’t seem like what one should consider a public API.

1 Like