How can I use a Polymorphic Domain Object Container in a custom plugin extension?


(Maxime Lefrançois) #1

Hello,

I’m developing a plugin (using Gradle 4.6 but I can migrate) and would like to use a PolymorphicDomainObjectContainer in my custom plugin extension to name individual source files, or set of source files. For example

myExtension {
  sources {
    source1 SingleSource {
      file = "src/file1.txt"
      propertySpecificToSingleSource = true
   } 
    source2 SourceSet {
      files = ["src/file2.txt", "src/file3.txt"]
      propertySpecificToSourceSet = true
   } 
}

I saw that issue is marked Won’t Fix:
https://issues.gradle.org/browse/GRADLE-3544

What is the easiest way to define, use, configure, a PolymorphicDomainObjectContainer ?

Best,
Maxime


(steve) #2

+1. I would like to do the very same thing in a custom plugin. I can create a NamedDomainObjectContainer no problem (Project#container). But I have no idea how to get a reference to a PolymorphicDomainObjectContainer. Is there some magic like all NamedDomainObjectContainer impls are also PolymorphicDomainObjectContainer impls?