This tutorial explains how to set up a clean and new Grails 1.1.1 mavenized project using the
grails-maven-plugin.
Prepare Maven environment
Edit your ~/.m2/settings.xml as follows :
<pluginGroups>
<pluginGroup>org.grails</pluginGroup>
</pluginGroups>
…
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<pluginRepositories>
<pluginRepository>
<id>snapshots.codehaus.org</id>
<url>http://snapshots.repository.codehaus.org/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
The minimal pom.xml for using Grails 1.1.1
The OSCache and HsqlDB are used by Grails by default, and can be changed with little configuration. <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<dependencies>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-gorm</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.2.3.5521</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>oscache</artifactId>
<version>2.4</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<pluginManagement />
<plugins>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.1-SNAPSHOT</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Initialize a new Grails project
mvn initialize
You will then notice that the application version is not correct :
Application expects grails version [1.1], but GRAILS_HOME is version [1.1.1] - use the correct Grails version or run 'grails upgrade' if this Grails version is newer than the version your application expects.
Now edit <project>/application.properties
app.grails.version=1.1.1
A web.xml is missing : (since we are using a WAR packaging)
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
So let’s create
an empty “web.xml” file, in “<project>/src/main/webapp/WEB-INF”
Compile the Grails project, and run it
mvn clean install
And so it should work…
mvn grails:run-app
Enjoy.