# Custom plugin problem

**URL:** <https://discuss.gradle.org/t/custom-plugin-problem/43816>\
**Category:** Help/Discuss\
**Created:** [September 6, 2022, 2:12pm UTC](https://discuss.gradle.org/t/custom-plugin-problem/43816 "2022-09-06T14:12:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maksim](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Maksim](https://discuss.gradle.org/u/Maksim)\
**Post date:** [September 6, 2022, 2:12pm UTC](https://discuss.gradle.org/t/custom-plugin-problem/43816/1 "2022-09-06T14:12:03Z")

</div>

Hello everybody! I ran into a problem. I am developing a gradle plugin in Kotlin. There are several extensions in my plugin. The project is built on a composite build so I can immediately test my plugin, composite build example ([GitHub - cortinico/kotlin-gradle-plugin-template: 🐘 A template to let you started with custom Gradle Plugins + Kotlin in a few seconds](https://github.com/cortinico/kotlin-gradle-plugin-template)). My extensions work fine, but when I publish and add a dependency to another project, those extensions become unavailable, although new tasks appear. What could be the reason?

```gradle
// Plugin
open class CorePlugin : Plugin<Project> {
    override fun apply(target: Project) {
        val buildConfigs = target.extensions.create<BuildConfig>("buildConfigs")
        // tasks creation
    }
}

```

```gradle
// Extension
open class BuildConfig {
    private val params: MutableMap<String, Any> = mutableMapOf()

    fun putString(fieldName: String, value: String) {
        params[fieldName] = value
    }
}

```

```gradle
// Extension usage in build.gradle (unresolved after publication)
buildConfigs {
    putString("Tara", "+529943241241")
    putString("Max", "+529943241241")
    putString("Sasha", "+529943241241")
}

```

Also after publishing I can’t add plugin dependency via block `plugin { ... }`, only use `apply(plugin = "...")`

---

<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:** [September 27, 2022, 12:48pm UTC](https://discuss.gradle.org/t/custom-plugin-problem/43816/2 "2022-09-27T12:48:27Z")

</div>

The last sentence is the key actually.  
Type-safe accessors are only generated for plugins that you apply using the `plugins { ... }` block, not using the legacy `apply` mechanism.  
If you apply using the legacy mechanism, you need to use the more verbose syntax and configure by type instead of using the `buildConfigs` accessor.

If the `plugins { ... }` block is not working, you are probably just publishing the code artifact, but not the marker artifact, but that is just a wild guess unless you provide the build script / release process.
