How this works/processed? ``` @Inject prote...
# community-support
k
How this works/processed?
Copy code
@Inject
    protected ObjectFactory getObjectFactory() {
        throw new UnsupportedOperationException(); // << not thrown during execution?
    }
Would inject work just for ObjectFactory field ?
1
t
Basically, Gradle will create a subclass that overrides the method to return an
ObjectFactory
and that won't call the
super
method, so won't throw. It works for a handful of services: https://docs.gradle.org/current/userguide/custom_gradle_types.html#service_injection It's more idiomatic nowadays to make the class and method abstract (and then you don't have to annotate it with
@Inject
)
but Gradle itself still uses that approach a lot.
k
That was the second question, reading all Tasks sources and see that most of them abstract. Was bit confusing
🪄 1
v
Since when do you not need
@Inject
@Thomas Broyer? You still need it even when using an interface or abstract methods, don't you?
🤔 1
t
Oops! I got things mixed up with managed properties I think. Indeed you still need the
@Inject
, and this is documented in the link I gave above 🤦‍♂️ 🤣
👌 1
🫡 1