# Cannot call custom plugin method an external build script

**URL:** <https://discuss.gradle.org/t/cannot-call-custom-plugin-method-an-external-build-script/5043>\
**Category:** Old Forum Archive\
**Created:** [June 6, 2014, 9:52pm UTC](https://discuss.gradle.org/t/cannot-call-custom-plugin-method-an-external-build-script/5043 "2014-06-06T21:52:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ipoo\_Doh](https://avatars.discourse-cdn.com/v4/letter/i/d6d6ee/32.png) [@Ipoo\_Doh](https://discuss.gradle.org/u/Ipoo_Doh)\
**Post date:** [June 6, 2014, 9:52pm UTC](https://discuss.gradle.org/t/cannot-call-custom-plugin-method-an-external-build-script/5043/1 "2014-06-06T21:52:00Z")

</div>

Hi

i have a custom plugin that exposes certain tasks and methods. I apply the plugin and can call any of its task or method from my main build file but When i try to do the same in an external build script, it cannot load the custom methods but its able to run the tasks fine.

Main Build file

```gradle
//build.gradle
apply plugin: 'MyCustomPlugin'
import com.MyCompany.gradle.UtilityMethods
  task MainBuildFileTask << {
    UtilityMethods.PrintFileContent(project,"SomeFile.txt")
}

```

gradle MainBuildFileTask =\> It works gradle customTask =\> It works

but if i move this code to an external buil script that i include in the main script it doesnt work

```gradle
//ExternalScript.gradle
  apply plugin: 'MyCustomPlugin'
import com.MyCompany.gradle.UtilityMethods
  task externalScriptTask << {
    UtilityMethods.PrintFileContent(project,"SomeFile.txt")
}

```

```gradle
//build.gradle
apply from: 'ExternalScript.gradle'

```

gradle externalScriptTask =\> It doesnt work

calling custom task from the plugin works gradle customTask =\> It works

It complains, '\> Could not find property ‘UtilityMethods’ on task ':externalScriptTask ‘.’

I have tried playing with where i do the ‘apply plugin’ and ‘import’ steps and even using the fully qualified name with no luck. any help is greatly appreciated

Cheers Ipoo Doh

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [June 8, 2014, 4:18am UTC](https://discuss.gradle.org/t/cannot-call-custom-plugin-method-an-external-build-script/5043/2 "2014-06-08T04:18:00Z")

</div>

You’ll need to move the ‘buildscript’ block that declares the plugin dependency to ‘ExternalScript.gradle’.

---

<div class="post-metadata">

**Author:** ![Ipoo\_Doh](https://avatars.discourse-cdn.com/v4/letter/i/d6d6ee/32.png) [@Ipoo\_Doh](https://discuss.gradle.org/u/Ipoo_Doh)\
**Post date:** [June 9, 2014, 4:48pm UTC](https://discuss.gradle.org/t/cannot-call-custom-plugin-method-an-external-build-script/5043/3 "2014-06-09T16:48:00Z")

</div>

Thanks Peter that did it, I had the buildscript block in the init.gradle script that worked fine as long as i dont load the plugin from the external build script.

Does this mean, i have to re-do all the work that is done by init.gradle script in the external build script as well.

Thanks Ipoo
