Creating a plugin in the project source directory
We have defined the plugin and used the plugin in the same build file. We will see how we can extract the plugin code from the build file and put it in a separate source file in the project source directory. Also, we will learn how we can test the plugin.
When we define the plugin in our build file, we cannot re-use it in other projects. And 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, for a multi-project build, we can re-use the plugin in the other projects of the multi-project build.
We already learned 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 create the directory buildSrc/src/main/groovy/sample
. In...