Last updated by pledbrook 3 years ago
This page is deprecated. You should refer to section 4.5 of the user guide

The current Maven plugin is based on, but effectively supercedes, the version created by the guys at Octo who did a great job. Until this page is updated, you'll still want to use the documenation over at octo.

Preparation

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

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!

If you are running grails 1.2-M3, you must set GRAILS_HOME due to GRAILS-5220 (Fixed in Grails 1.2-M4)

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.2.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

if you see the following message:

::::::::::::::::::::::::::::::::::::::::::::::
::          UNRESOLVED DEPENDENCIES         ::
::::::::::::::::::::::::::::::::::::::::::::::
:: org.hibernate#hibernate-commons-annotations;3.3.0.ga: not found
:: javassist#javassist;3.8.0.GA: not found
::::::::::::::::::::::::::::::::::::::::::::::
edit grails-app/conf/BuildConfig.groovy:19 and uncomment the following line:
mavenCentral()
call again:
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 .

The default mvn setup DOES NOT supply sufficient memory to run the Grails environment. We recommend that you add the following environment variable setting to prevent poor performance:

export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=192m"

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
To use GORM add the following line to application.properties :
plugins.hibernate=1.2.0

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
1.1.11.11.1
1.2.01.2.01.2.0
1.2.11.2.11.2.1
1.2.21.2.21.2.2

Raising issues

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