Slackbot
11/15/2023, 12:18 PMGiuseppe Barbieri
11/15/2023, 12:24 PMval developers type and get rid of ListProperty, instantiating a new instance myself with action.execute(object : Developer) or switch the plugin extension from interface to abstract/open class?Thomas Broyer
11/15/2023, 1:55 PMobjects and/or Developer interface.
For objects, inject an ObjectFactory inside your plugin and pass it to your extension. For Developers I think you'd have to move it to its own *.kt file (as a rule of thumb, any class that's part of your API should live in its own *.kt or *.java rather than in the *.gradle.kts of your precompiled script plugin)Vampire
11/15/2023, 2:18 PMObjectFactory from the plugin to the extension, I think you can also directly let Gradle inject the ObjectFactory to the extension.
You might also consider using a DomainObjectSet<Developer> instead of a ListProperty<Developer>.Thomas Broyer
11/15/2023, 2:22 PMDomainObjectSet<Deleveloper> but never used it myself; also it's a Set, not a `List`; there's NamedDomainObjectList too, but then it's "named")Vampire
11/15/2023, 2:24 PMDomainObjectCollection<Developer> I think, unless it should be named objects, then of course Named...Giuseppe Barbieri
11/15/2023, 2:44 PMGiuseppe Barbieri
11/15/2023, 2:45 PMObjectFactory automaticallyGiuseppe Barbieri
11/15/2023, 2:45 PMI think you'd have to move it to its ownOk, I'll do itfile (as a rule of thumb, any class that's part of your API should live in its own*.ktor*.ktrather than in the*.javaof your precompiled script plugin)*.gradle.kts
Vampire
11/15/2023, 2:46 PMobjects you do use project.getObjects() which then causes the problem of "capturing project".
By injecting it into your extension you get a reference that does not need to capture project to be used.Giuseppe Barbieri
11/15/2023, 2:47 PMVampire
11/15/2023, 2:48 PM@get:Inject val objects: ObjectFactory in an interfaceGiuseppe Barbieri
11/15/2023, 2:48 PMGiuseppe Barbieri
11/15/2023, 8:50 PMbuild.gradle.kts script by calling the respective organization { } DSL, which is
val organization: Property<Organization>
fun organization(action: Action<Organization>) = action.execute(organization.get())
I get
> Cannot query the value of extension 'scijava' property 'organization' because it has no value available.
Because organization hasn't been yet instantiated by Gradle
At this point, I guess I can only switch the extension to a class and manually instantiate that by objects.newInstance<>(() or do I have another choice?Vampire
11/15/2023, 10:13 PMProperty<Organization>Vampire
11/15/2023, 10:14 PMProperty only makes sense for values that are expected to be set, so that you can wire them together and lazily get the set value.
But if it is always the one same organization, there is absolutely no need to use a Property, it only makes the API needlessly more complex.Giuseppe Barbieri
11/16/2023, 8:55 AMVampire
11/16/2023, 10:24 AMorganization = Organization(...) or do you mean just "set all fields for the organization" like organization { ... }Giuseppe Barbieri
11/16/2023, 10:26 AMorganization dsl and set all of its fieldGiuseppe Barbieri
11/16/2023, 10:27 AMorganization hasnt been called and if any of the field hasnt been setVampire
11/16/2023, 10:30 AMGiuseppe Barbieri
11/16/2023, 10:38 AMorganization DSL construct will automatically use objects to instantiate the Property<Organization>Vampire
11/16/2023, 12:27 PMorganization { ... } and then organization = ... the first will be discarded if that is a problem.Giuseppe Barbieri
11/16/2023, 1:15 PMVampire
11/16/2023, 1:46 PMorganization { ... }, right?Giuseppe Barbieri
11/16/2023, 1:47 PMVampire
11/16/2023, 1:48 PMorganization = ... or is the user only expected to do organization { ... }Giuseppe Barbieri
11/16/2023, 1:48 PMGiuseppe Barbieri
11/16/2023, 1:49 PMVampire
11/16/2023, 1:50 PMProperty<Organization> at all, but simply have an Organization field. And then when you add the extension in your plugin, there use objects.newInstance<Organization>() to create the organization and set the field.Vampire
11/16/2023, 1:51 PMval which is better as it should not be changed.Vampire
11/16/2023, 1:52 PM