How do I configure `CommonExtension` in a precompi...
# gradle
n
How do I configure
CommonExtension
in a precompiled script plugin? I am getting
Extension of type 'CommonExtension<?, ?, ?, ?>' does not exist.
Copy code
configure<CommonExtension<*, *, *, *>> { 
    defaultConfig {
        ...
    }
}
v
Find out which plugin adds it and wrap it in a
pluginManager.withPlugin(...) { ... }
call
n
Thank you. I mean I am creating common Gradle scripts as follows and want each other scripts inherit from a parent one. Parent one tries to configure
CommonExtension
and I am getting the above exception
Copy code
apply<LibraryCommonPlugin>()

configure<CommonExtension<*, *, *, *>> {

    defaultConfig {
        ...
    }

    testOptions {
        unitTests {
            isReturnDefaultValues = true
        }
    }

    buildTypes {
        getByName(TYPE_DEBUG) {
            isMinifyEnabled = false
        }
        maybeCreate(TYPE_INTERNAL).apply {
            isMinifyEnabled = true
        }
        getByName(TYPE_RELEASE) {
            isMinifyEnabled = true
        }
    }
}
v
Well, I cannot guess what
LibraryCommonPlugin
is. But I guess it is another convention plugin of yours that applies the plugin that should add the
CommonExtension
whatever that it, right? Then it should actually work from the information you showed. The error might be in the details you are not showing. Btw. from the syntax and the Slack you are asking from, I'd say you are using Kotlin DSL. So I'd recommend you do not use the legacy apply method, but properly use the
plugins { ... }
block, which also works to apply sibling precompiled script plugins. Because if you do, then you also get the type-safe accessors generated and can use the
whateverExtensionThatIs { ... }
syntax instead of
configure<CommonExtension<*, *, *, *>> { ... }
.