Big Chungus
06/09/2022, 9:30 PMExtensiblePolymorphicDomainObjectContainer
usage? For whatever reason it refuses to construct my custom gradle types that regular NamedDomainObjectContainer
has no issues with (even after registering bindings)...Vampire
06/09/2022, 10:01 PMVampire
06/09/2022, 10:02 PMBig Chungus
06/09/2022, 10:06 PMBig Chungus
06/09/2022, 10:07 PMVampire
06/09/2022, 10:10 PMregisterBinding(Foo::class, Foo::class)
and registerBinding(Bar::class, Bar::class)
was enough to make the container work with Foo
and Bar
Vampire
06/09/2022, 10:10 PMNamed
?Big Chungus
06/09/2022, 10:13 PMBig Chungus
06/09/2022, 10:14 PMVampire
06/09/2022, 10:14 PMBig Chungus
06/09/2022, 10:17 PMBig Chungus
06/09/2022, 10:18 PMVampire
06/09/2022, 10:19 PMVampire
06/09/2022, 10:19 PMBig Chungus
06/09/2022, 10:21 PMBig Chungus
06/09/2022, 10:23 PMVampire
06/09/2022, 10:23 PMinterface Base : Named {
val url: Property<String>
}
interface Foo : Base {
@get:Inject
val objects: ObjectFactory
val children: DomainObjectSet<FooChild>
fun child(nick: String) {
children.add(createChild(nick))
}
private fun createChild(nick: String): FooChild {
return objects.newInstance<FooChild>().also { child ->
child.nick.set(nick)
}
}
}
interface FooChild {
val nick: Property<String>
}
abstract class MyExtension {
@get:Inject
abstract val objects: ObjectFactory
val baz = objects.polymorphicDomainObjectContainer(Base::class).apply {
registerBinding(Foo::class, Foo::class)
}
}
Big Chungus
06/09/2022, 10:30 PMVampire
06/09/2022, 10:31 PMVampire
06/09/2022, 10:40 PMVampire
06/09/2022, 10:44 PMVampire
06/09/2022, 11:46 PMBig Chungus
06/10/2022, 8:15 AMBig Chungus
06/10/2022, 8:19 AM./gradlew :kotlin-gradle-plugin-integration-tests:kgpJsTests --tests "org.jetbrains.kotlin.gradle.JsIrConfigurationCacheIT.testBrowserDistribution"
Big Chungus
06/10/2022, 8:20 AMBig Chungus
06/10/2022, 8:21 AMVampire
06/10/2022, 9:24 AMHah got curious, didn't you? :DI don't need to become, I always am. :-D
Ok, so first, you need to change the factories to type bindings hereAh, I see, I misunderstood actually. I thought you didn't get it managed even with
registerFactory
and went some other route, that state being the broken one.
That it works with ObjectFactory#newInstance
but not with the binding is imho even stranger.
Note that you'll need JDKs 6, 7, 8 and 9+ installed for the project to configure (I used sdkman and gradle toolchains detected them just fine)I happen to have these already. 🙂 6, 7, 8, 11, 16 I'm more concerned that build will eat up my disk space actually. 😄
Oh and feel free to go watch a movie or something, the project can take up to an hour for first time configuration :DActually, I went to sleep after opening the project in IntelliJ and after 42 minutes the sync was complete. So maybe that was the waiting time already. 🙂
Vampire
06/10/2022, 2:20 PM--debug-jvm
it is not hit.Big Chungus
06/10/2022, 2:56 PMBig Chungus
06/10/2022, 2:56 PMBig Chungus
06/10/2022, 2:58 PMBig Chungus
06/10/2022, 2:59 PMVampire
06/10/2022, 3:06 PMVampire
06/10/2022, 3:06 PMKotlinWebpackRule
line 38Big Chungus
06/10/2022, 3:06 PMBig Chungus
06/10/2022, 3:07 PMBig Chungus
06/10/2022, 3:08 PM.run
folder at the rootBig Chungus
06/10/2022, 3:11 PMVampire
06/10/2022, 3:18 PMenabled.convention(false)
calls getEnabled()
which tries to use the object factory service which it states is not available.Big Chungus
06/10/2022, 3:20 PMBig Chungus
06/10/2022, 3:20 PMVampire
06/10/2022, 3:21 PMBig Chungus
06/10/2022, 3:21 PMBig Chungus
06/10/2022, 3:21 PMVampire
06/10/2022, 3:24 PMorg.gradle.api.internal.tasks.TaskDependencyResolveException: Could not determine the dependencies of task ':kotlinNpmInstall'.
[...]
Caused by: org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException: Could not create task ':rootPackageJson'.
[...]
Caused by: org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException: Could not create task ':app:browserProductionWebpack'.
[...]
Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssRule.
[...]
Caused by: org.gradle.internal.service.UnknownServiceException: No service of type ObjectFactory available in DefaultServiceRegistry.
at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:291)
at org.gradle.internal.instantiation.generator.ManagedObjectFactory.getObjectFactory(ManagedObjectFactory.java:121)
at org.gradle.internal.instantiation.generator.ManagedObjectFactory.newInstance(ManagedObjectFactory.java:86)
at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssRule_Decorated.getEnabled(Unknown Source)
at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule.<init>(KotlinWebpackRule.kt:38)
at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssRule.<init>(KotlinWebpackCssRule.kt:26)
at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssRule_Decorated.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator$InvokeConstructorStrategy.newInstance(AsmBackedClassGenerator.java:1969)
at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:468)
at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
... 227 more
Big Chungus
06/10/2022, 3:24 PMBig Chungus
06/10/2022, 3:25 PMVampire
06/10/2022, 3:25 PMBig Chungus
06/10/2022, 3:26 PMVampire
06/10/2022, 3:27 PMBig Chungus
06/10/2022, 3:27 PMVampire
06/10/2022, 3:28 PMVampire
06/10/2022, 3:29 PMVampire
06/10/2022, 4:06 PMVampire
06/10/2022, 4:07 PMBig Chungus
06/10/2022, 4:45 PMVampire
06/10/2022, 4:45 PMVampire
06/10/2022, 4:46 PMorg.gradle.internal.service.UnknownServiceException: No service of type ObjectFactory available in default services.
where it works perfectly fine with 7.3.2Big Chungus
06/10/2022, 4:47 PMVampire
06/10/2022, 4:47 PMBig Chungus
06/10/2022, 4:48 PMBig Chungus
06/10/2022, 4:49 PMVampire
06/10/2022, 4:51 PMI also found it extremely annoying that adding Named interface to noarg abstract class errors complaining that getName() is not implemented where all other object factories just implement it for youMaybe same root problem? Because when I made my interfaces abstract classes and the properties abstract it still worked fine.
Big Chungus
06/10/2022, 4:51 PMVampire
06/10/2022, 4:54 PMabstract class Base : Named {
abstract val url: Property<String>
}
abstract class Foo : Base {
@get:Inject
abstract val objects: ObjectFactory
abstract val children: DomainObjectSet<FooChild>
fun child(nick: String) {
children.add(createChild(nick))
}
private fun createChild(nick: String): FooChild {
return objects.newInstance<FooChild>().also { child ->
child.nick.set(nick)
}
}
}
abstract class FooChild {
abstract val nick: Property<String>
}
abstract class MyExtension {
@get:Inject
abstract val objects: ObjectFactory
val baz = objects.polymorphicDomainObjectContainer(Base::class).apply {
registerBinding(Foo::class, Foo::class)
}
}
Big Chungus
06/10/2022, 4:54 PMVampire
06/10/2022, 4:56 PMOh, while I have your attention, do you have any good links to read up on Namer usage? How do I inject it into the object containers?No, but what do you mean how to inject? Iirc if you have an object that is not
Named
you can alternatively supply a Namer
for your child type so that the name can be derived.Big Chungus
06/10/2022, 4:56 PMVampire
06/10/2022, 5:03 PMBig Chungus
06/10/2022, 5:04 PMBig Chungus
06/10/2022, 5:05 PMVampire
06/10/2022, 5:07 PMNamer
yet. 😞Big Chungus
06/10/2022, 5:07 PMVampire
06/10/2022, 5:07 PMBig Chungus
06/10/2022, 5:08 PMBig Chungus
06/10/2022, 5:08 PMVampire
06/10/2022, 5:08 PMBig Chungus
06/10/2022, 5:09 PMVampire
06/10/2022, 5:09 PMVampire
06/10/2022, 5:14 PMEven DomainObjectContainer docs mention Namer as an alternativeWhere? Especially as that class does not exist 😄
Big Chungus
06/10/2022, 5:14 PMVampire
06/10/2022, 5:15 PMNamer
besides the getNamer
methodBig Chungus
06/10/2022, 5:15 PMVampire
06/10/2022, 5:21 PMNamer
must of course be public API even if you cannot supply one, unless methods like getNamer
are moved to internal too.Vampire
06/10/2022, 5:21 PMBig Chungus
06/10/2022, 5:22 PMVampire
06/10/2022, 5:22 PMVampire
06/10/2022, 5:23 PMNamed
or if it is a Map
have a name
key or actually just have a property name
even if it does not implement Named
Vampire
06/10/2022, 5:25 PMNamed
interface is probably actually most useful if you want Gradle to just implement it for you.Big Chungus
06/10/2022, 5:25 PMVampire
06/10/2022, 5:26 PMregisterBinding
😄Vampire
06/10/2022, 5:26 PMBig Chungus
06/10/2022, 5:28 PMYep, well it works, if you do not use registerBinding 😄Not really, I still had to implement them properly and annotate my constructor with @Inject which made my kotlin classes ugly. There really should be
@constructor:Annotation
selector so I could at least put those annotations on top of the classVampire
06/10/2022, 5:32 PMObjectFactory#newInstance
now, it should also work to just declare that you want to have Named
implemented.
Because ObjectFactory#newInstance
should do the same that registerBinding
does from 7.3 onBig Chungus
06/10/2022, 5:33 PMVampire
06/10/2022, 5:34 PMgetName
override in KotlinWebpackRule
and the constructors and it should probably just still workVampire
06/10/2022, 5:35 PMBig Chungus
06/10/2022, 5:39 PMVampire
06/10/2022, 5:40 PMBig Chungus
06/10/2022, 5:40 PMVampire
06/10/2022, 5:43 PM-Xmx3g
and had 4 other small projects open while having it open.
Was not super fast, but at least no crash.Big Chungus
06/10/2022, 5:44 PMVampire
06/10/2022, 5:45 PMVampire
06/10/2022, 5:45 PMBig Chungus
06/10/2022, 5:46 PMCaused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssRule.
after removing my constructors and getName implementationsBig Chungus
06/10/2022, 5:48 PMVampire
06/10/2022, 5:49 PMgetName
implementation or also changes the constructor.Vampire
06/10/2022, 5:49 PMVampire
06/10/2022, 5:51 PMObjectFactory#named
instead of ObjectFactory#newInstance
Big Chungus
06/10/2022, 5:51 PMVampire
06/10/2022, 5:51 PMBig Chungus
06/10/2022, 5:51 PMVampire
06/10/2022, 5:52 PMBig Chungus
06/10/2022, 5:52 PMabstract val mode: Property<String>
Big Chungus
06/10/2022, 5:52 PMnamed()
docsVampire
06/10/2022, 5:52 PMVampire
06/10/2022, 5:52 PMBig Chungus
06/10/2022, 5:53 PMVampire
06/10/2022, 5:53 PMBig Chungus
06/10/2022, 5:54 PMVampire
06/10/2022, 5:54 PMattributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_API))
}
Vampire
06/10/2022, 5:54 PMBig Chungus
06/10/2022, 5:54 PMVampire
06/10/2022, 6:06 PMregisterBinding(Foo::class, Foo::class)
by
registerFactory(Foo::class.java) {
objects.newInstance<Foo>(it)
}
and it still works fine, so the name parameter seems to get added to the constructorBig Chungus
06/10/2022, 6:11 PM@Inject
annotated constructor. Does that mean that I still need to annotate my noarg constructor?Vampire
06/10/2022, 6:13 PM@Inject
missing on constructorVampire
06/10/2022, 6:18 PM@Inject
to the empty constructor it works.Vampire
06/10/2022, 6:19 PM