This message was deleted.
# plugin-development
s
This message was deleted.
d
Copy code
class SeatGeekPlugin : Plugin<Project> {

    override fun apply(target: Project) = with(target) {
        val arch2 = extensions.create("arch2", Arch2PluginExtension::class.java)

        afterEvaluate {
            if (arch2.isConfigured) {
                val moduleSetup = archetypeConfigToModuleSetup(target, arch2.archetypeConfig)

                moduleSetup.plugins.forEach { plugin ->
                    println("Plugin: $plugin")

                    when (plugin) {
                        is Plugin.Class -> project.plugins.apply(plugin.clazz)
                        is Plugin.Id -> project.plugins.apply(plugin.id)
                    }
                }

                moduleSetup.dependencies.forEach { dep ->
                    when (dep) {
                        is Dependency.Maven -> target.dependencies.add(dep.configuration.asGradleConfigurationString(), dep.coordinates)
                        is Dependency.Module -> target.dependencies.module("${dep.configuration.asGradleConfigurationString()} ${dep.path}")
                    }
                }
            }
        }
    }
...
}
v
The plugin is applied in time. Indeed immediately. Even though you use the legacy way of applying it instead of the
plugins
block. But you explicitly delay most of the work to later, after the build script was evalutated using
afterEvaluate
which is almost never a good idea to use.
d
hmm, it seemed that if I didn't include it in afterEvaluate {} then the arch2 extension wasn't yet parsed from the build.gradle
So with this feedback I tried something different -- injecting project into the extension and then applying the necessary plugins from the view{} block and that seems to work. Is that the "right" way?
v
Of course the extension is not yet configured without
afterEvalutate
, as the
apply
is of course before the extension. When the plugin is applied it adds the extension, so it cannot be configured before the plugin is applied. I'm not sure how you mean it exactly, but I guess yes, having a method in
view
instead of a property and reacting to the method call.
d
It's working! Configuring the project from within the Extension implementation party gradlephant
👌 1