# Settings gradle custom plugin problem

**URL:** https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044
**Category:** Help/Discuss
**Created:** [March 2, 2023, 12:39pm UTC](https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044 "2023-03-02T12:39:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Prosto](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Prosto](https://discuss.gradle.org/u/Prosto)
#### Post date: [March 2, 2023, 12:39pm UTC](https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044/1 "2023-03-02T12:39:13Z")

</div>

I created my plugins for a Plugin project.  
With them connected, there are no problems in build.gradle.kts, they work fine. By making another plugin for setttings.gradle.kts of type Plugin and including it in setttings.gradle.kts. I’m starting to have problems with the plugin for projects  
Type com.android.build.api.dsl.ApplicationExtension not present  
What needs to be done to make this work?

---

<div class="post-metadata">

### Author: ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)
#### Post date: [March 2, 2023, 2:03pm UTC](https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044/2 "2023-03-02T14:03:29Z")

</div>

It’s totally unclear (to me) what you try to do, and what error you get.  
Can you maybe create an [MCVE](https://stackoverflow.com/help/mcve) to clarify what you are trying and what problem you have?

---

<div class="post-metadata">

### Author: ![Prosto](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Prosto](https://discuss.gradle.org/u/Prosto)
#### Post date: [March 3, 2023, 10:19am UTC](https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044/3 "2023-03-03T10:19:02Z")

</div>

I have this plugin for `build.gradle.kts (app)`, connect it to the block `plugins. It works great.

```gradle
internal class AndroidApplicationConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) = target.run {

        with(pluginManager) {
            apply("com.android.application")
            apply("org.jetbrains.kotlin.android")
        }

        extensions.configure<ApplicationExtension> {
            configureKotlinAndroid(this)
            defaultConfig.targetSdk = 33
        }
    }
}

```

Created a plugin for `setting.gradle.kts (project)`, connect it to the block `plugins`. I get an error `Caused by: java.lang.TypeNotPresentException: Type com.android.build.api.dsl.ApplicationExtension not present` for this `AndroidApplicationConventionPlugin`

```gradle
class Test : Plugin<Settings> {
    override fun apply(target: Settings) = target.run {

    }
}

```

All my plugins are in `buildSrc/convention-plugin-module` and registered in `build.gradle.kts(convention-plugin-module)`. Why am I suddenly getting this error?

---

<div class="post-metadata">

### Author: ![Prosto](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Prosto](https://discuss.gradle.org/u/Prosto)
#### Post date: [March 6, 2023, 7:01am UTC](https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044/4 "2023-03-06T07:01:31Z")

</div>

@Vampire, I created my plugin `AndroidApplicationConventionPlugin`of this type `Plugin<Project>`  
Plugged it in `build.gradle.kts (app)`. It works great.

```gradle
internal class AndroidApplicationConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) = target.run {

        with(pluginManager) {
            apply("com.android.application")
            apply("org.jetbrains.kotlin.android")
        }

        extensions.configure<ApplicationExtension> {
            configureKotlinAndroid(this)
            defaultConfig.targetSdk = 33
        }
    }
}

```

Then I made a plugin `SettingsConventionPlugin` for `settings.gradle.kts (project)`. Connected here in the block `plugins`

```gradle
class SettingsConventionPlugin : Plugin<Settings> {
    override fun apply(target: Settings) = target.run {

    }
}

```

And I get an error for `AndroidApplicationConventionPlugin`

```gradle
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin 'subholder.android.application'.
	at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:173)
	at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:137)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.lambda$applyPlugin$1(DefaultPluginRequestApplicator.java:148)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:199)
	... 189 more
Caused by: java.lang.TypeNotPresentException: Type com.android.build.api.dsl.ApplicationExtension not present
	at org.gradle.api.reflect.TypeOf.captureTypeArgument(TypeOf.java:299)
	at org.gradle.api.reflect.TypeOf.<init>(TypeOf.java:96)
	at AndroidApplicationConventionPlugin$apply$lambda$1$$inlined$configure$1.<init>(TypeOfExtensions.kt:28)
	at AndroidApplicationConventionPlugin.apply(AndroidApplicationConventionPlugin.kt:28)

```

All my plugins are in `buildSrc/convention-plugin-module` and registered in `build.gradle.kts(convention-plugin-module)`.  
What did i do wrong?

---

<div class="post-metadata">

### Author: ![Prosto](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Prosto](https://discuss.gradle.org/u/Prosto)
#### Post date: [March 6, 2023, 9:50am UTC](https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044/5 "2023-03-06T09:50:31Z")

</div>

I created a working plugin `AndroidApplicationConventionPlugin` like `Plugin<Project>` for `build.gradle.kts (app)`. It works without problems.

```gradle
internal class AndroidApplicationConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) = target.run {

        with(pluginManager) {
            apply("com.android.application")
            apply("org.jetbrains.kotlin.android")
        }

        extensions.configure<ApplicationExtension> {
            configureKotlinAndroid(this)
            defaultConfig.targetSdk = 33
        }
    }
}

```

Then i created a plugin `SettingsConventionPlugin` for `settings.gradle.kts (project)`. Connect it to the block `plugins` in the `settings.gradle.kts` file.

```gradle
internal class SettingsConventionPlugin : Plugin<Settings> {
    override fun apply(target: Settings) = target.run {

    }
}

```

And then i get an error for `AndroidApplicationConventionPlugin`

```gradle
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin 'subholder.android.application'.
	at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:173)
	at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:137)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.lambda$applyPlugin$1(DefaultPluginRequestApplicator.java:148)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:199)
	... 189 more
Caused by: java.lang.TypeNotPresentException: Type com.android.build.api.dsl.ApplicationExtension not present
	at org.gradle.api.reflect.TypeOf.captureTypeArgument(TypeOf.java:299)
	at org.gradle.api.reflect.TypeOf.<init>(TypeOf.java:96)
	at AndroidApplicationConventionPlugin$apply$lambda$1$$inlined$configure$1.<init>(TypeOfExtensions.kt:28)
	at AndroidApplicationConventionPlugin.apply(AndroidApplicationConventionPlugin.kt:28)

```

What am I doing wrong?

---

<div class="post-metadata">

### Author: ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)
#### Post date: [March 8, 2023, 3:07pm UTC](https://discuss.gradle.org/t/settings-gradle-custom-plugin-problem/45044/6 "2023-03-08T15:07:44Z")

</div>

Let me ask again, can you maybe create an [MCVE](https://stackoverflow.com/help/mcve)? What you provided neither fulfills the C(omplete) nor V(erifiable).
