To make a task reusable for other projects, we must have a way to distribute the task. Also, other projects that want to use the task must be able to find our task. We will see how to publish our task in a repository and how other projects can use the task in their projects.
We have seen how to place the task implementation from the build file in the
buildSrc directory. The
buildSrc directory is similar to a normal Gradle build project, so it is easy to create a standalone project for our task. We only have to copy the contents of the
buildSrc directory to our newly created project directory.
Let's create a new project directory and copy the contents of the
buildSrc directory. We must edit the
build.gradle file of our standalone project. Gradle implicitly added the Groovy plugin and dependencies on the Gradle API and Groovy for us when the
build.gradle file is in the
buildSrc directory. Now we have a standalone project and we must add these dependencies...