- Grails Tutorial
- Grails - Home
- Grails - Overview
- Grails - MVC Architecture
- Grails - Creating an Application
- Grails - The Command Line
- Grails - Application Profiles
- Object Relational Mapping (GORM)
- Grails - The Web Layer
- Grails - Groovy Server Pages
- Grails - Web Services
- Grails - Validation
- Grails - Plugins
Grails - Creating and Installing Plugins
Description
In Grails, plugin can be created by running the following command
grails create-plugin myplugin
The above command will create plugin directory with name myplugin. In Grails, you should consider requirement of the plugin like, does the plugin requires a web environment or it can be used with other profiles. Depending on the requirement the profiles can be used like plugin or web-pluginprofile. The usage of profile with create-plugin command is shown below:
grails create-plugin myplugin --profile=plugin
You have to note that, the plugin name should not contain more than one capital letter. As it is a grails project (web profile), you can immediately test your plugin by running the following command:
grails run-app
The structure of a Grails plugin should contain MypluginGrailsPlugin.groovy file in C:\myplugin\src\main\groovy\myplugin, otherwise it is not regarded as a plugin. The plugin class defines metadata about the plugin.
Table below shows additional information, that can be mentioned about the plugin:
S.N. | Types & Description |
---|---|
1 | title It indicates one-line heading of your plugin. |
2 | grailsVersion It shows the range of Grails that the plugin supports. |
3 | author It indicates plugin author’s name. |
4 | authorEmail It represents plugin author’s contact e-mail. |
5 | developers Any additional developers beyond the author specified above. |
6 | description A brief description of plugin and its features features. |
7 | documentation URL of the plugin’s documentation. |
8 | license This field indicates license of the plugin. |
9 | issueManagement This field indicates issue tracker of the plugin. |
10 | scm This field indicates source code management location of the plugin. |
You can check the sample file Quartz Grails plugin for demonstration.
Installation
Plugins can be made available for application use by running the below command:
grails install
After running the above command, plugin will be installed in your local Maven cache. You have to declare a dependency of the plugin in your build.gradle file to use it in the application as shown below:
compile "org.grails.plugins:quartz:0.1"
You can setup the plugin as part of multi project build by following below steps:
- Step 1: Create the application and the plugin
Run the following commands for creating the application and the plugin:
grails create-app myapplication grails create-plugin multiproplugin
- Step 2: Create a settings.gradle file
Now create settings.gradle file in the project directory and place the following code in the file:
include "myapplication", "multiproplugin"
The directory structure should be as follows:
grailsproject - settings.gradle - myapplication - build.gradle - multiproplugin - build.gradle
- Step 3: Declare a project dependency on the plugin
In build.gradle file of application folder, mention below code to declare a dependency on the plugin:.
grails { plugins { compile project(':multiproplugin') } }
- Step 4: Run the application
Now move into the app folder and run the application using below command.
cd myapplication $ grails run-app
To Continue Learning Please Login
Login with Google