Cannot call custom plugin method an external build script

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

//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

//ExternalScript.gradle
  apply plugin: 'MyCustomPlugin'
import com.MyCompany.gradle.UtilityMethods
  task externalScriptTask << {
    UtilityMethods.PrintFileContent(project,"SomeFile.txt")
}
//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

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

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