Plugin
Plugins can extend other plugins. For example, war plugin extends java plugin. That means, we can remove apply plugin: 'java' if we are using war plugin.
Script plugin
Script Plugins are plugins that live in a .gradle file and can be imported in other gradle build files.
We can create a plugin using local script file. In order to create a new script plugin, create a file scriptPlugin.gradle and put there the plugin code.
// scriptPlugin.gradle
task myScriptPluginTask(description: 'Testing script plugins', group: 'Testing') {
if (project.hasProperty('myName')) {
inputs.property('myName', myName)
inputs.file file('gradlew')
doLast {
println "Hi there $myName :) "
println file('gradlew').text
}
}
}Then we can import that plugin in our build.gradle file.
We can execute the task from the script plugin.
Object plugin
Object plugin can live in its own Gradle project, in src folder. Or the object plugin can be placed into buildSrc if it is supposed to live next to project.
We need to add the internal dependencies into Gradle build.
Lets create a object plugin. First create the plugin class and put this class into buildSrc/src/main/groovy.
To try out plugin extensions, create another class, next to the MyPlugin class.
Then create a new properties file in resource folder META-INF/gradle-plugins/myplugin.properties that declares name of the plugin. Name of this file says what is the name of the plugin.
If we don't create the myplugin.properties file, we would have to apply
But because we provided the properties file, we can reference the plugin by its name.
Before we continue, we can configure the plugin using the plugin extension.
IDE integration
We can use IDE plugins to generate project files (to avoid project IDE files committed in source code repository, like Git).
Last updated
Was this helpful?