# How to apply a plugin in settings.grade

**URL:** <https://discuss.gradle.org/t/how-to-apply-a-plugin-in-settings-grade/6281>\
**Category:** Old Forum Archive\
**Created:** [April 14, 2014, 11:26am UTC](https://discuss.gradle.org/t/how-to-apply-a-plugin-in-settings-grade/6281 "2014-04-14T11:26:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwass](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@mwass](https://discuss.gradle.org/u/mwass)\
**Post date:** [April 14, 2014, 11:26am UTC](https://discuss.gradle.org/t/how-to-apply-a-plugin-in-settings-grade/6281/1 "2014-04-14T11:26:00Z")

</div>

I read some topics about applying a plugin in settings.gradle but none of them seems to work for me.

In settings.gradle I have this four lines of code and I would like to outsource them to a gradle plugin which I can then apply in settings.gradle.

```gradle
rootProject.children.each { project ->
                                            String fileBaseName = project.name.replaceAll("\p{Upper}") { "-${it.toLowerCase()}" }
    project.buildFileName = "${fileBaseName}.gradle"
}

```

I tried applying this plugin by the name:

```gradle
Plugin with id 'plugin-to-apply' not found.

```

By the classname:

```gradle
Could not find property 'com' on settings 'my-project'

```

Is there any other way to import a plugin to settings.gradle or is it a fail configuration?

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [April 17, 2014, 12:47pm UTC](https://discuss.gradle.org/t/how-to-apply-a-plugin-in-settings-grade/6281/2 "2014-04-17T12:47:00Z")

</div>

Hello, where did you declare the plugin?

For a plugin that is applied in the settings.gradle file you have three options:

- declare the plugin class directly in the settings.gradle file (not that useful for production but good for testing) \* declare the plugin in the buildSrc project \* resolve the plugin as a third party dependency

To resolve a plugin as a thirdparty dependency you need to declare a buildscript block and declare the dependency (& repository) to resolve the plugin. Be aware that the buildscript block in your build.gradle does not work for this as the build.gradle file is evaluated _AFTER_ the settings.gradle file. You have to declare the buildscript block in your settings.gradle file. example:

```gradle
buildscript{
 repositories{
  mavenCentral();
 }
 dependencies{
  classpath "org.acme:settingsplugin:1.0"
 }
}
  apply plugin 'settingsplugin'
  // declare some projects
include 'shared'
include 'api'
include 'services:webservice'
  rootProject.name = 'settingsplugin'

```

We have plans and already working on reducing the boilerplate for declaring plugins but this is currently WIP.

hope that helps!

cheers, René

---

<div class="post-metadata">

**Author:** ![mwass](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@mwass](https://discuss.gradle.org/u/mwass)\
**Post date:** [April 22, 2014, 11:03am UTC](https://discuss.gradle.org/t/how-to-apply-a-plugin-in-settings-grade/6281/3 "2014-04-22T11:03:00Z")

</div>

Hello Rene,

thanks for your answer.

I declared my plugin directly in settings.gradle and tried to specify the plugin name like so:

```gradle
apply plugin: 'plugin-to-apply'

```

META-INF/gradle-plugins/plugin-to-apply.properties:

```gradle
implementation-class=com.plugins.MyPlugin

```

and got the error like id not found. See the error message in the first post.

My second try was to declare in settings.gradle the plugin by its classname like so:

```gradle
apply plugin: com.plugins.MyPlugin

```

and got again an error message:

```gradle
Could not find property 'com' on settings 'my-project'

```

I’m fine to go with the plugin classname in settings.gradle but can’t get it to run.

Do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [April 22, 2014, 12:43pm UTC](https://discuss.gradle.org/t/how-to-apply-a-plugin-in-settings-grade/6281/4 "2014-04-22T12:43:00Z")

</div>

Can you show me how you declare the classpath to point to your plugin implementation?

---

<div class="post-metadata">

**Author:** ![mwass](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@mwass](https://discuss.gradle.org/u/mwass)\
**Post date:** [April 23, 2014, 9:25am UTC](https://discuss.gradle.org/t/how-to-apply-a-plugin-in-settings-grade/6281/5 "2014-04-23T09:25:00Z")

</div>

I have in my gradle distribution in the directory init.d resolveplugins.gradle file with this content:

```gradle
initscript{
                                                                             repositories{
                                                                           maven{
                                                                                  url = "http://someCompany.com/nx/ct/gr/pub"
                 }
                                                                       }
                                                                               dependencies{ classpath "com.someCompany:my.plugins:@VERSION@" }
}
                                                                                                                                                                 allprojects {
                                                                           buildscript{
                                                                            repositories{
                                                                           maven{
                                                                                  url = "http://someCompany.com/nx/ct/gr/pub"
                         }
                                                                       }
                                                                               dependencies{ classpath "com.someCompany:my.plugins:@VERSION@" }
        }
                                                                               apply plugin:com.someCompany.plugins.BasePlugin
           }

```
