Just to explain a bit, following @DeKaNszn answer:
Depending on where is the script situated, you will need to extend your build.gradle
with it.
If the script is in the root, yes including
apply from: "$rootDir/test.gradle"
is going to extend you the script you have applied it to, then if your test.gradle
is in the root and you want to access the task defined in that script from your project, or any subproject, you will need to apply it in the build.gradle
in this project, because otherwise gradle will not read it automatically and configure the task.
build.gradle
is read automatically, therefore extending it with your script is going to configure the task you want to use and have it visible for Gradle.
There is a kind of a convention, to put your scripts in the gradle
directory, and keep build.gradle
and settings.gradle
only in the root, but is just a preference.
But if you would like to follow this idea you will need to give it a path where to apply from, like above, and always use Gradle variables pointing to directories. $rootDir
, $buildDir
, etc.