# Simple buildSrc plugin issue

**URL:** <https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [August 25, 2016, 12:04pm UTC](https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189 "2016-08-25T12:04:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anonymity](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Anonymity](https://discuss.gradle.org/u/Anonymity)\
**Post date:** [August 25, 2016, 12:04pm UTC](https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189/1 "2016-08-25T12:04:00Z")

</div>

Hi,

I’m trying to write a plugin in buildSrc and apply it to the root project. When trying to apply it, I get plugin not found.

Project structure

```
   build.gradle
+ buildSrc
     build.gradle
   + src
      + main
         + groovy
            CustomPlugin.groovy

```

Root build.gradle

```
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'customplugin'

depedencies {
    testCompile 'junit:junit:4.12'
}

```

buildSrc build.gradle

```
apply plugin: "groovy"
apply plugin: "java"

dependencies {
    compile localGroovy()
    compile gradleApi()
}

```

Plugin code

```
import org.gradle.api.Plugin
import org.gradle.api.Project

class CustomPlugin implements Plugin<Project>
{
    @Override
    void apply(Project target)
    {
        println 'Applying CustomPlugin'
    }
}

```

**gradle clean build** gives Plugin with id ‘customplugin’ not found.

Any hints?

Thank you

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [August 25, 2016, 5:18pm UTC](https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189/2 "2016-08-25T17:18:15Z")

</div>

You forgot to add the properties file that tells Gradle about the mapping from plugin ID to implementation class. Have a look at the [user guide](https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project) about plugins.

---

<div class="post-metadata">

**Author:** ![Anonymity](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Anonymity](https://discuss.gradle.org/u/Anonymity)\
**Post date:** [September 1, 2016, 10:32am UTC](https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189/3 "2016-09-01T10:32:23Z")

</div>

Thanks for your reply, but isn’t that required only for standalone projects? Being in buildSrc, I thought the there’s no need for an extra mapping.

[https://docs.gradle.org/current/userguide/custom\_plugins.html#sec:custom\_plugins\_standalone\_project](https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project)

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [September 1, 2016, 11:49am UTC](https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189/4 "2016-09-01T11:49:15Z")

</div>

You always need a mapping, how else is Gradle going to know what ID your plugin should have?

---

<div class="post-metadata">

**Author:** ![Anonymity](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Anonymity](https://discuss.gradle.org/u/Anonymity)\
**Post date:** [September 30, 2016, 1:45pm UTC](https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189/5 "2016-09-30T13:45:04Z")

</div>

Thanks a lot for the help

---

<div class="post-metadata">

**Author:** ![kwilliams3](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kwilliams3/32/7077_2.png) [@kwilliams3](https://discuss.gradle.org/u/kwilliams3)\
**Post date:** [November 23, 2018, 8:30pm UTC](https://discuss.gradle.org/t/simple-buildsrc-plugin-issue/19189/6 "2018-11-23T20:30:47Z")

</div>

If you want to implement a plugin into your buildscript, then you have two options.

**Option 1**  
`apply plugin: YourCustomPluginClassName`

**Option 2**  
`plugins { id 'your.custom.plugin.id' }`

`apply plugin:` is used when specifying your plugin by its class name (ex. `apply plugin: JavaPlugin`)  
`plugins { }` is used when specifying your plugin by its id (ex. `plugins { id 'java' }`)  
See [Gradle Plugins by tutorialspoint](https://www.tutorialspoint.com/gradle/gradle_plugins.htm) for reference

If you choose Option 1, then your custom plugin will need to be brought into your build script by 1 of 3 ways.

1. You can code it directly within your Gradle build script.
2. You can put it under **buildSrc** (ex. **buildSrc/src/main/groovy/MyCustomPlugin** ).
3. You can import your custom plugin as a jar in your `buildscript` method.  
See [Gradle Goodness by Mr. Haki](http://mrhaki.blogspot.com/2016/01/gradle-goodness-getting-information.html) for information about the `buildscript` method.

If you choose Option 2, then you need to create a plugin id. Create the following file **buildSrc/src/main/resources/META-INF/gradle-plugins/[desired.plugin.id].properties**. Copy and paste `implementation-class=desired.plugin.id` into your newly created .properties file. Replace ‘desired.plugin.id’ with your desired plugin id.  
See [Custom Plugins by Gradle](https://docs.gradle.org/current/userguide/custom_plugins.html) for more info.
