This tutorial describes the way of creating Gradle standalone custom plugin. It covers the following topics
- Creating task, and using it in Custom plugin
- Stand alone Custom plugin
- Short plugin id
- Customize Gradle setting using settings.gradle
Project info :
Gradle version : 1.1
OS platform : Ubuntu 12.10
Prerequisite : Basic understanding of Gradle script.
Creating the Stand alone custom plugin
-
|-custom-plugin | |-plugin | |-src | |-main | | |-groovy | | | |-com | | | |-code4reference | | | |-gradle | | |-resources | | | |-META-INF | | | |-gradle-plugins | |-test | | |-groovy | | | |-com | | | |-code4reference | | | |-gradle |-user
Here plugin directory contains all source code and resource files whereas the user directory contains the consumer script which uses custom plugin. Execute the following command to create the directory structure. Here groovy folder contains the source code package.
$ mkdir -p custom-plugin/plugin/src/main/groovy/com/code4reference/gradle $ mkdir -p custom-plugin/plugin/src/main/resources/META-INF/gradle-plugins $ mkdir -p custom-plugin/user
-
Every plugin should have a implementation class to extend the Plugin class. Let’s define the plugin class.
package com.code4reference.gradle; import org.gradle.api.*; class Code4ReferencePlugin implements Plugin { def void apply(Project project) { //c4rTask task has been defined below. project.task('c4rTask')