Friday, September 04, 2009

A few mins with Grails (Creating a plugin)

GrailsImage via Wikipedia

Lately I found myself playing around with Grails and I've been appreciating right away the plugins mechanism (Grails website: creating a Plugin).

With a simple:
> grails create-plugin Utils

or even with a simpler (the script will ask you to specify the name of the plugin later on):
> grails create-plugin

you will be able to generate the structure of a Grails plugin that you will notice is really similar to the structure of a Grails application (in italic the directories):

.classpath -> Eclipse .classpath file. It includes all the references to the folders in the project that are going to be in the classpath and all the references to the libraries for making your grails project run. The libraries are expressed through the GRAILS_HOME variable under the form GRAILS_HOME/dist/grails-web-1.1.1.jar. The directories that are included in the classpath are typically (you can detect them easily in Eclipse if you import the project just created as "existing project"):
  • src/java
  • src/groovy
  • grails-app/conf
  • grails-app/controllers
  • grails-app/domain
  • grails-app/services
  • grails-app/taglib
  • test/integration
  • test/unit
.project -> Eclipse .project file
.settings -> Eclipse .settings directory

Utils-test.launch -> can be used to run the unit tests
Utils.launch -> can be used to run the application
Utils.tmproj

UtilsGrailsPlugin.groovy -> The plugin class defines the version of the plugin and optionally various hooks into plugin extension points.

application.properties -> Contains a few lines to describe the details of the plugin/application:
#utf-8
#Fri Sep 04 10:12:01 EDT 2009
app.version=0.1
app.servlet.version=2.4
app.grails.version=1.1.1
app.name=Utils
build.xml -> It is an Ant file that contains a set of targets, allowing to resolve dependencies declared in the Ivy file, to compile and run the sample code, produce a report of dependency resolution, and clean the cache or the project. Ivy is a subproject of Ant.
grails-app -> directory containing the main components of a Grails application/plugin: controllers, services... (see classpath)
ivy.xml -> Ivy file containing the description of the dependencies of a module. Ivy (Ivy website) supports dependency resolution (grails does not support Maven).
ivysettings.xml -> file for Ivy configuration
lib -> directory containing the list of libraries for running the application
scripts -> Grails scripts
src -> directory with the source codes in both java and groovy (see classpath)
test -> directory collecting all Grails unit tests: Grails supports the concepts of unit and integration testing. Unit testing is for small focused, fast loading tests that don't load supporting components. Integration testing is for tests that load the surrounding environment (it supports injection).
web-app -> contains the web components of the Grails project

Reblog this post [with Zemanta]

No comments: