Slackbot
05/17/2022, 3:33 PMThomas Broyer
05/17/2022, 3:49 PMExtensiblePolymorphicDomainObjectContainer ? I don't think we can use plain PolymorphicDomainObjectContainer without using internal classes.Vampire
05/17/2022, 3:52 PMtasks or repositories, so like
foo {
create<A>("a") {
// configure a
}
create<B>("b") {
// configure b
}
}Vampire
05/17/2022, 3:52 PMfoo {
a("a") {
// configure a
}
b("b") {
// configure b
}
}Vampire
05/17/2022, 3:55 PMinterface ConfigureNexusExtension {
val foo: PolymorphicDomainObjectContainer<BaseOfAAndB>
}
but it seems not to be.Thomas Broyer
05/17/2022, 3:56 PMThomas Broyer
05/17/2022, 3:58 PMa("a") { … } syntax though (not without Kotlin/Groovy extensions)Vampire
05/17/2022, 3:58 PMNamed, you need to register the types manually, ...
Or I do it completely wrongVampire
05/17/2022, 3:58 PMThomas Broyer
05/17/2022, 4:04 PMThomas Broyer
05/17/2022, 4:05 PMRené
05/17/2022, 4:06 PMRené
05/17/2022, 4:07 PMVampire
05/17/2022, 4:21 PMReportingExtension usage is even newly added, just with 7.4 with the report aggregation changes.
But I still don't fully grasp it.
If I just do
val foo = objects.polymorphicDomainObjectContainer(BaseOfAAndB::class)
like is shown in those examples, I get
org.gradle.api.InvalidUserDataException: Cannot create a MavenRepository because this type is not known to this container. Known types are: (None)
[...]
Caused by: org.gradle.api.internal.NoFactoryRegisteredForTypeException
[...]
Instead I have to do
val foo = objects.polymorphicDomainObjectContainer(BaseOfAAndB::class).apply {
registerBinding(A::class, A::class)
registerBinding(B::class, B::class)
}
to make it work. 😕Vampire
05/17/2022, 4:22 PMSteve Ebersole
05/18/2022, 6:00 PMname(type) syntax to work thoughSteve Ebersole
05/18/2022, 6:06 PMproject.getExtensions().add( "SpecialType", SpecialType.class );
// or
project.getExtensions().add( "SpecialType", SpecialType.class.getName() );
I wonder if that is what my attempts here missed.
Anyway, aside from that particular form not working that project successfully uses such a containerVampire
05/18/2022, 8:01 PMname(type) form should probably simply work from Groovy DSL if you import the type class, or do the extensions trick so that it looks like it were auto-imported (should be the first form for the extensions trick, as you need the class instance as argument, not the name), where in the linked code is the container used? I'm probably just blind.Steve Ebersole
05/18/2022, 8:23 PMSteve Ebersole
05/18/2022, 8:24 PMSteve Ebersole
05/18/2022, 8:25 PMSteve Ebersole
05/18/2022, 8:26 PMSteve Ebersole
05/18/2022, 8:27 PMSteve Ebersole
05/18/2022, 8:29 PMSteve Ebersole
05/18/2022, 8:30 PMSteve Ebersole
05/18/2022, 8:31 PMVampire
05/19/2022, 3:02 PMmethodMissing and so on and compose the container and so on.
And additionally you use custom factories which I don't need, all the domain objects for me can directly be created that's why registerBinding is enough for me.
But in the examples the other showed in the Gradle sources even that is not necessary but just works and I wonder why. 😕Steve Ebersole
05/19/2022, 3:04 PMThomas Broyer
05/19/2022, 4:07 PMregisterBinding or registerFactory.Steve Ebersole
05/19/2022, 4:08 PMmethodMissing is very much Groovy. IIRC you use exclusively KotlinVampire
05/19/2022, 4:14 PMmethodMissing and it is maybe appropriate there. If you would be in the container directly, it shouldn't be necessary as Gradle should provide the necessary magic for newName(Type) { ... } iirc.
But yes, I use Kotlin DSL wherever possible.
But if I would develop something for publishing, I'd make it convenient for both DSLs too of course.Vampire
05/19/2022, 4:22 PMAFAICT, uses in Gradle all useAh, yeah, didn't look right. Probably too tired yesterday. And because it's too scattered in the Gradle sources. 😄 The extensions just create the container and then some more specific plugins likeorregisterBinding.registerFactory
JacocoReportAggregationPlugin or JvmTestSuites register the bindings.Vampire
05/19/2022, 4:25 PMval foo = objects.polymorphicDomainObjectContainer(Base::class).apply {
registerBinding(A::class, A::class)
registerBinding(B::class, B::class)
}
but that indeed seems to be the way to go.Vampire
05/19/2022, 4:34 PMVampire
05/19/2022, 4:41 PM