I need to inject the `ExtensionContainer` into an ...
# community-support
z
I need to inject the
ExtensionContainer
into an extension (to manipulate another extension). How can I do this?
Copy code
> Unable to determine constructor argument #2: missing parameter of type ExtensionContainer, or no service of type ExtensionContainer.
Copy code
abstract class ArtifactoryPublisherExtension @Inject constructor(
    layout: ProjectLayout,
    // neither work
    // extensions: ExtensionContainer
    // publishingExtension: org.gradle.api.publish.PublishingExtension
) {
a
Only services (like ProjectLayout) are automatically injectable, and for additional args you'll have to pass them in manually when creating the extension (or when using
ObjectFactory.newInstance()
)
Copy code
project.extensions.create(
  "artifactoryPublisher",
  ArtifactoryPublisherExtension::class, 
  project.extensions, // add additional arg
)
❤️ 1
👍 1
z
that’s a bummer, but thank you!
t
Fwiw, there's no the extension container, there's one extension container per
ExtensionAware
, and many many objects in Gradle are extension aware (all tasks, many extensions themselves, etc. anything created through
ObjectFactory
or similar actually IIUC)