Last updated by 1 year ago

Page: Developer - Maven Integration, Version:16

The Grails Maven integration consists of an archetype and a plugin.

The Maven archetype

The source for the archetype is located in Git. The archetype defines the project template when creating a Grails project with the command:

mvn archetype:generate \\
    -DarchetypeGroupId=org.grails \\
    -DarchetypeArtifactId=grails-maven-archetype \\
    -DarchetypeVersion=1.3.2 \\
    -DgroupId=example -DartifactId=my-app

To fully generate the Grails project structure use the following command (similar to the command line)

cd my-app
mvn initialize

To update the archetype you need to specify a new archetype version in ARCHETYPE_HOME/pom.xml and specify the Grails version it relates to in src/main/resources/archetype-resources/pom.xml by updating the following three dependenices:

<dependency>
  <groupId>org.grails</groupId>
  <artifactId>grails-bootstrap</artifactId>
  <version>1.3.2</version>
</dependency>
<dependency>
  <groupId>org.grails</groupId>
  <artifactId>grails-crud</artifactId>
  <version>1.3.2</version>
</dependency>
<dependency>
  <groupId>org.grails</groupId>
  <artifactId>grails-gorm</artifactId>
  <version>1.3.2</version>
</dependency>

If the new archetype requires a new version of the Grails plugin this can be specified too:

<plugins>
      <plugin>
        <groupId>org.grails</groupId>
        <artifactId>grails-maven-plugin</artifactId>
        <version>1.3.2</version>
        ...

To test out archetype changes you should install the archetype locally with:

mvn install

And then once you are satisfied deploy the changes with

mvn deploy

The Maven Plugin

The source for the Maven plugin is also in Git. A local version can be installed by doing:

mvn install

Deployment can be done with:

mvn deploy

Release Procedure

In order to deploy the Grails artifacts to the Codehaus repositories, you will have to do some setup - see the Codehaus Maven repository instructions for the full details. Most of the work has already been done, but to perform the actual upload, you will need to add the following to your Maven settings (usually ~/.m2/settings.xml ):

<settings>
  …
  <servers>
    <server>
      <id>codehaus.org</id>
      <username>USERNAME</username>
      <password>PASSWORD</password>
    </server>
  </servers>
  …
</settings>

Because Maven caches the files it downloads, you have to be careful when testing that you aren't picking up artifacts from previous runs/builds. Before publishing a release, you must always try the Maven integration out with a clean cache. To do that, just follow these steps:

  1. Remove everything under ~/.m2/repository/ .
  2. Install latest version of grails-maven-archetype by running mvn install from your working copy.
  3. Install latest version of grails-maven-archetype by running mvn install from your working copy.
  4. Install latest version of grails-maven-plugin by running mvn install .
  5. Install latest version of Grails by running ant maven-install .
You can then test the Maven integration, although make sure that you are using the correct versions in your project POMs and when creating a project from the archetype. See Maven Integration for more info.

If the version in the pom.xml of the plugin ends with -SNAPSHOT then the plugin will be deployed to the Codehaus snapshot repository otherwise to the real one.