Maven Integration

The current Maven plugin is based on, but effectively supercedes, the version created by the guys at Octo who did a great job.

Preparation

In order to try the new plugin, all you need is Maven 2 installed and set up. In fact, you should unset the GRAILS_HOME environment variable when running Maven with a Grails project. This is because you no longer need to install Grails separately to use it with Maven!

The Maven 2 integration for Grails has been designed and tested for Maven 2.0.9 and above and will not work with prior version of Maven 2

One piece of configuration that may help is setting up a plugin group in your Maven settings file ( $HOME/.m2/settings.xml ):

<settings><pluginGroups>
    <pluginGroup>org.grails</pluginGroup>
  </pluginGroups>
</settings>
Also, remove the com.octo.mtg plugin group if you have it set up.

Just do it!

Without further ado, let's create our Mavenised Grails project:

mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate \
    -DarchetypeGroupId=org.grails \
    -DarchetypeArtifactId=grails-maven-archetype \
    -DarchetypeVersion=1.0 \
    -DgroupId=example -DartifactId=my-app
Choose whichever group ID and artifact ID you want for your application, but everything else must be as written. This will create a new Maven project with a POM and a couple of other files. What you won't see is anything that looks like a Grails application. So, the next step is to create the project structure that you're used to:
mvn initialize
Now we have a Grails application all ready to go. The plugin integrates into the standard build cycle, so you can use the standard Maven phases to build and package your app: mvn clean , mvn compile , mvn test , mvn package .

You can also take advantage of some of the Grails commands that have been wrapped as Maven goals:

  • grails:console
  • grails:create-controller
  • grails:create-domain-class
  • grails:create-integration-test
  • grails:create-pom
  • grails:create-script
  • grails:create-service
  • grails:create-tag-lib
  • grails:create-unit-test
  • grails:exec
  • grails:generate-all
  • grails:generate-controller
  • grails:generate-views
  • grails:install-plugin
  • grails:install-templates
  • grails:list-plugins
  • grails:package
  • grails:run-app
  • grails:run-app-https
  • grails:uninstall-plugin

Example Usage

(first execute archetype as above to create your project)

mvn grails:list-plugins

mvn grails:install-plugin -DpluginName=jsecurity

mvn initialize

Debugging

Maven can be launched in debug mode using the "mvnDebug" command. To launch your Grails application in debug, simply run:

mvnDebug grails:run-app
The process will be suspended on startup and listening for a debugger on port 8000.

If you need more control of the debugger, this can be specified using the MAVEN_OPTS environment variable, and launch Maven via the default "mvn" command:

MAVEN_OPTS="-Xdebug 
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" mvn grails:run-app

Executing scripts

Some plugins have extra scripts for generating config files or other artifacts. For instance, the Quartz plugin has a create-job script which is invoked in a non-Maven environment via:

grails create-job

Execute scripts like this in a Maven environment this way:

mvn grails:exec -Dcommand="create-job"

Other versions

During the beta and RC cycles, several versions of the plugin and archetype are released. Here's a table of the versions you need to use for a given version of Grails:

GrailsPluginArchetype
1.1-beta1--
1.1-beta20.41.0-beta2
1.1-beta31.0-beta31.0-beta3
1.1-RC11.0-RC11.0-RC1
1.1-RC21.0-RC21.0-RC2
1.1-SNAPSHOT1.0-SNAPSHOT1.0-SNAPSHOT
1.11.01.0

Raising issues

If you come across any problems with the Maven integration, please raise a JIRA issue as a sub-task of GRAILS-3547.

16 Comments

  • Gravatar
    hi i use mvn grails:run-app it's work, but use mvn grails:run-app-https,it's could not be work, and i got this exception org.codehaus.groovy.grails.cli.ScriptNotFoundException
    May 06, 2009 07:05 AM baallee
  • Gravatar
    Great work! My 2 cents are that you have to be inside your artifact directory, in this case, my-app, to run "mvn initialize".

    I'm looking forward to see more maven commands documented here.

    May 13, 2009 00:05 AM gmaggess
  • Gravatar
    Is the source code for the plugin available anywhere? I have looked into the POM of the Maven plugin but there was no SCM section.
    May 26, 2009 16:05 PM andreasch
  • Gravatar
    Source code is here: http://github.com/grails/grails/tree/master
    May 30, 2009 19:05 PM Xymor
  • Gravatar
    Just removed the {{-DarchetypeRepository=http://snapshots.repository.codehaus.org}} as it is no longer required with non-snapshot version 1.0 ( {{-DarchetypeVersion=1.0}}) and causes {{mvn}} to hang with a virgin Maven installation (i.e. no mirrors, no proxy and local repository empty).
    May 31, 2009 02:05 AM rsaddey
  • Gravatar
    Re: Source code: I'm confused.

    http://github.com/grails/grails/tree/master shows 1.0-RC2 as the latest version from February, although the http://repo1.maven.org/maven2/org/grails/grails-maven-archetype/ already has version @1.0@. Where does 1.0 come from?

    May 31, 2009 03:05 AM rsaddey
  • Gravatar
    Hello, I just upgraded Grails from 1.1 to 1.1.1. I ran "grails upgrade" on my project and now when running "mvn grails:run-app" I get > Application expects grails version 1.1.1 (+), but GRAILS_HOME is version 1.1 (+) <

    I checked my GRAILS_HOME and it is pointing to 1.1.1 What can I do?

    D.

    Jun 04, 2009 13:06 PM dxb54
  • Gravatar
    Say you want your production environment to be in effect for a given run.

    without the maven grails plugin you would run a command like this ->

    grails prod run-app

    But the mvn command does not like the 'prod' string.. You need to run this>

    mvn -Dgrails.env=prod grails:run-app

    regards.

    • Chris
    Jun 05, 2009 16:06 PM buildlackey
  • Gravatar
    To get the grails-maven plugin to work with grails 1.1.1, make these changes to your app.

    edit the application.properties file: app.grails.version=1.1.1

    in pom.xml, change these 2 dependencies to version 1.1.1

    <dependency> <groupId>org.grails</groupId> <artifactId>grails-crud</artifactId> <version>1.1.1</version> </dependency>

    <dependency> <groupId>org.grails</groupId> <artifactId>grails-gorm</artifactId> <version>1.1.1</version> </dependency>

    add this dependency

    <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>1.2.3.5521</version> <scope>runtime</scope> </dependency>

    change this plugin to version 1.1-SNAPSHOT

    <build> <plugins> <plugin> <groupId>org.grails</groupId> <artifactId>grails-maven-plugin</artifactId> <version>1.1-SNAPSHOT</version> … </plugin> </plugins> </build>

    Jun 06, 2009 11:06 AM paulwoods
  • Gravatar
    Paul, Thanks for the suggestion. Unfortunately I am still getting the following: Application expects grails version 1.1.1 (+), but GRAILS_HOME is version 1.1-SNAPSHOT (+)

    DB

    Jun 08, 2009 15:06 PM dxb54
  • Gravatar
    Is it possible to specify grails plugin in pom.xml to get it automatically installed during {{mvn package}} goal? This will be very useful for my continuous integration server.
    Jun 09, 2009 09:06 AM andrew.osipenko
  • Gravatar
    I have built my Grails project using maven plugin. Works great. Then I did maven eclipse:eclipse to create an eclipse project. I tried to access all commands from grails with eclipse and configure within Eclipse. Has anyone manage to configure Eclipse with a maven generated grails project ?

    Thanks

    Jun 10, 2009 12:06 PM fellahst
  • Gravatar
    Has anyone done a successful mvn release:prepare? I'm having issues with the application.properties having the wrong app.version.

    I had this working with the octo plugin by filtering the application.properties with ${pom.version} at mvn clean phase.

    Cheers,

    Christiaan

    Jun 17, 2009 10:06 AM cveerman
  • Gravatar
    Yes and no… I have to edit application properties manually to bring it into sync and then re-issue the 'mvn release:prepare' command.
    Jun 19, 2009 12:06 PM kellinwood
  • Gravatar
    I'm using eastwood chart plugin 0.5 which has a dependency on an unrelased version of google charts, 0.5 http://www.grails.org/JFreeChart+Eastwood+Plugin. So I had to pass an parm when I ran the google chart plugin, grails install-plugin http://svn.codehaus.org/grails-plugins/grails-google-chart/trunk/grails-google-chart-0.5.0.zip

    How do I do that with this plugin?

    Currently, I get

    @Plugin eastwood-chart-0.5 (+) not installed, resolving.. Reading remote plugin list ...

    unzip (+) Expanding: grails1.1.1pluginsgrails-eastwood-chart-0.5.zip into C:...pluginseastwood-chart-0.5

    Plugin dependency googleChart (+) not found. Attempting to resolve… ...

    Release 0.5.0 was not found for this plugin. Type 'grails plugin-info google-chart'@

    Jun 25, 2009 15:06 PM bchaplin1
  • Gravatar
    We want to share the domain classes between a grails app and a standard groovy app. Therefore we would like to keep the domain classes outside the grails app. How can we use the plugin to let the grails app know, that it has a dependency to external domain classes?

    klaus.

    Jun 26, 2009 08:06 AM klausb

Post a Comment