Last updated by 5 years ago

Page: Maven Integration, Version:16

The Maven 2 integration for Grails is currently a work in progress. If you would like to try it out, we very much welcome feedback on bugs, improvements that can make, or any other related comments.

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


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 ):

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 \
    -DarchetypeRepository= \
    -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

To Debug

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

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:


Raising issues

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