Slackbot
02/01/2022, 2:22 PMThomas Broyer
02/01/2022, 2:55 PMproject.extensions.getByType(SourceSetContainer::class.java) (or project.the<SourceSetContainer>() or similar) for Java projects.Thomas Broyer
02/01/2022, 2:57 PMproject.the<CommonExtension>().sourceSets (or use ApplicationExtension if you know you'd in an Android application).Javi
02/01/2022, 3:00 PMthe and extensions is it is lazy so you don't need afterEvaluate?Thomas Broyer
02/01/2022, 3:04 PMthe() is a Kotlin DSL extension that only adds syntactic sugar: https://github.com/gradle/gradle/blob/v7.3.3/subprojects/kotlin-dsl/src/main/kotlin/org/gradle/kotlin/dsl/ExtensionAwareExtensions.kt#L27-L28rekire
02/01/2022, 3:45 PMthe extension function?Vampire
02/01/2022, 5:48 PMkotlinDsl() iircThomas Broyer
02/01/2022, 5:48 PMgradleKotlinDsl(), which you get automatically when applying the ``kotlin-dsl`` plugin (which also applies ``embedded-kotlin``, itself applying kotlin("jvm") version embeddedKotlinVersion )rekire
02/01/2022, 7:51 PMCommonExtension or ApplicationExtension classes? They are not in my class path by defaultrekire
02/01/2022, 7:53 PMThomas Broyer
02/01/2022, 8:00 PMcompileOnly if your plugin could work without it, implementation if it's required, this declaration will then set a minimum version, or you could use compileOnly anyway and let the user explicitly add the plugin to their buildscript classpath), I'd use the gradle-api artifact then, that only exposes public APIs.rekire
02/01/2022, 8:12 PMThomas Broyer
02/01/2022, 8:14 PMcom.android.tools.build:gradle-api then 😉rekire
02/01/2022, 8:20 PMrekire
02/01/2022, 8:42 PMorg.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin 'my.plugin.name'
Extension of type 'ApplicationExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension]
My plugin is now basically:
open class MyPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = with(project) {
val androidSourceSets = project.the<ApplicationExtension>().sourceSets
// crash in line aboverekire
02/01/2022, 8:47 PMafterEvaluateVampire
02/01/2022, 9:04 PMafterEvaluate.
If your plugin cannot work without that plugin applied, then apply the plugin before configuring the extension.Vampire
02/01/2022, 9:05 PMpluginManager.withId("...") { ... }