Table of contents
1.
Introduction
2.
Grails-Plugins
3.
Creating and Installing Plugins
3.1.
Step 1
3.2.
Step 2
3.3.
Step 3
3.4.
Step 4
4.
Folder structure for Grails-Plugins
5.
Grails-Plugins Groups 
6.
Multi-Project and Plugins Builds
6.1.
Step 1: Create the plugin and the application. 
6.2.
Step 2: Make a file called settings.Gradle 
6.3.
Step 3: Declare the plugin as a dependency for the project.
6.4.
Step 4: Set the plugin to enable reloading
6.5.
Step 5: Run the application
7.
Plugin Repositories
8.
Creating New Artefact Types
9.
Frequently Asked Questions
9.1.
What is the use of grails?
9.2.
How do you run the grails project?
9.3.
Is the Grail comes under the framework of Java?
9.4.
Where are Grails-Plugins stored?
9.5.
What is Grail programming language?
10.
Conclusion
Last Updated: Mar 27, 2024
Easy

Grails-Plugins

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hello Ninja, We shall learn about the Grils-Plugins in this blog. The topic is pretty simple to understand. Grails is primarily a framework for web applications. By providing a few extension points, which let you expand all from the command line interface to the runtime configuration engine. Grails can be adjusted to almost any need.

Introduction

Grails-Plugins

The Grails framework uses Spring Boot's time-saving capabilities. Such as Spring-powered dependency injection, as it is built on top of it.

Grails-Plugins

A Grails plugin is a complete set of features that can be added to Grails applications. 

A Grails plugin's installation includes several features mentioned below:
 

  • It will update new techniques to the application's artifacts.
     
  • It also offers tag libraries.
     
  • It will give more classes and resources available to the application.
     
  • It will give new Grails commands.
     
  • It defines extra Spring beans.
     
  • Edit the produced web.xml.
     

The function of the Grails-plugins is to make access the application while installing it. The application properties file for the program just contains the name and version of the plugin. The application does not contain the plugin itself. After downloading, the application loads the plugin directly from $HOME/.grails.

The structure of the Grails plugins project is the same as that of a Grails application. With the exception of a setting file in the plugin's root directory.

Creating and Installing Plugins

Installing Plugins

Step 1

Start by executing the command to create Grails-plugins.

grails create-plugin <<Name Of the Plugin>>

Step 2

The name you enter will result in the creation of a web-plugin project. For instance, the grails create-plugin example would generate a brand-new model web-plugin project.

Grails create-plugin <<Name of the Plugins>> --profile=plugin

Step 3

Being a standard Grails project provides a lot of advantages. Including the ability to run your plugin and test it right away:

grails run-app

Step 4

The plugin descriptor class can be located in the src/main/groovy directory under the plugin package structure. The structure of a Grails-plugins is quite similar to that of a Grails application project.

import grails.Plugins.*

class ExampleGrailsPlugin extends Plugin {
  ...
}

Folder structure for Grails-Plugins

Folder structure for Grails-Plugins

For instance, you may use the service class provided by the findable plugin to conduct in-depth searches within your own domain classes.

The jQuery plugin you described provides a tag to include the jQuery.js file.

Grails-Plugins Groups 

Grails-Plugins Groups

Multi-Project and Plugins Builds

Step 1: Create the plugin and the application. 

Make a plugin and an application using the grails command:

$ grails create-app nameOfTheApp
$ grails create-plugin pluginName

Step 2: Make a file called settings.Gradle 

Create a Gradle settings file in the same directory with the following information in it:

Include "nameOfTheApp", "pluginName"

PROJECT_DIR
  - settings.Gradle
  - nameOfTheApp
    - build.Gradle
  - pluginName
    - build.Gradle

Step 3: Declare the plugin as a dependency for the project.

Declares a dependency on the plugin in the Plugins block of the build.Gradle of the application:

grails {
    Plugins {
        implementation project(':pluginName')
    }
}

Step 4: Set the plugin to enable reloading

The plugin directory's Gradle.properties file has to be updated or added to. A new variable exploded=true must be given in order for the plugin to add the exploded directories to the classpath.

Step 5: Run the application

In order to view the Gradle output, use the verbose flag while running the application using the Grails run-app command from the application directory's root:

$ cd myapp
$ grails run-app -verbose

The Gradle output will show you that the plugin sources have been created. And added to your application's classpath:

application's classpath
Application of Grails running on the environment at localhost:8080

Plugin Repositories

Grails Central Plugin Repository: Distributing Plugins 

Publishing to the official Grails Central Plugin Repository is the preferred method of plugin distribution. By doing this, the list-Plugins command will be able to see your plugin:

grails list-Plugins.

It provides a list of every plugin stored in the central repository. The plugin-info command will also access your plugin.

grails plugin-info [plugin_name].

It includes further details, such as its author's name and description.

Creating New Artefact Types

To learn about the available platform and participate in reloading, Plugins can easily submit their artefacts. The only thing left to do is to implement an Artefact Handler and register it in your main plugin class.

class MyGrailsPlugin {
    def artefacts = [ org.somewhere.MyArtefactHandler ]
    ...
}

Either handler classes (as mentioned above) or handler instances can be found in the artefacts list.

So, how do artefact handlers appear? 

Simply put, it is an ArtefactHandler interface implementation. A skeleton implementation can be easily improved to make things a little easier.
 

Every new artefact requires a wrapper class that implements Grails Class in addition to the handler itself. One very helpful transforms your artefact into a Spring bean that is auto-wired. Just like controllers and services and is called Abstract In ject able Grails Class.

Frequently Asked Questions

What is the use of grails?

Web applications may be swiftly created using Grails because of its scaffolding features, which enable quick project creation. The application can automatically wire itself using Grails' convention over the setting principle, which is based on naming conventions.

How do you run the grails project?

For Running a Grails Application and Deploying it, Go to the as-install /grails/samples/HelloWorld directory, for instance. Activate the grails run-app command. The Server will start in the background, and the application will run the same via the grails run-app command.

Is the Grail comes under the framework of Java?

Grails is a free and open-source framework for developing online applications that use the Apache Groovy language (based on the Java platform).

Where are Grails-Plugins stored?

The Plugins are, by default, located in. grails/version>/project>/Plugins. By adjusting the Grails project, you can change it.

What is Grail programming language?

The Groovy programming language is used by the open-source web application framework known as Grails. By holding to the "code by convention," offering a development platform, and keeping much of the setting information hidden from the developer, it is meant to be a high-productivity framework.

Conclusion

In this article, we have understood the Grails-Plugins. And also how to create and install it. We have covered the folder structure and groups of the Grails-Plugins. And also understand how the Plugins and Multi-Project Build. 

If you face any doubt, please comment, and we will love to answer your questions.

Want expertise in Python for your next web development project? Check out our course.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass