We have defined the plugin and used it in the same build file. We will see how to extract the plugin code from the build file and put it in a separate source file in the project source directory. Also, we will discuss how to test the plugin.
When we define the plugin in our build file, we cannot reuse it in other projects. We now have the definition and usage of the plugin in the same file. To separate the definition and usage, we can create the plugin class in the
buildSrc directory of a Gradle project. In a Gradle multi-project, we must use the
buildSrc directory of the root project. This means that for a multi-project build, we can reuse the plugin in other projects of the multi-project build.
We already discussed when we wrote a custom task that any sources in the
buildSrc directory are automatically compiled and added to the classpath of the project. First, we will create the
buildSrc/src/main/groovy/sample directory. In this directory...