Configure Eclipse for Grails + Maven

In three short steps :

1. Install Eclipse (3.5 SR1) Galileo  :

For Java EE developers.

http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR1/eclipse-jee-galileo-SR1-win32.zip

 

2. Add Groovy plugin

In Eclipse, via “Help / Install New Software…” menu : Add...

http://dist.springsource.org/release/GRECLIPSE/e3.5/

And check “Groovy-Eclipse Feature”.

 

3. Add m2eclipse plugin

Still via “Help / Install New Software…” : Add...

http://m2eclipse.sonatype.org/sites/m2e

And check “Maven Integration for Eclipse”.

Grails 1.2.0 Maven Integration : default pom.xml

1. Remember to configure your settings.xml for Grails.

2. Copy this pom.xml, run "mvn grails:run-app" and enjoy.

<?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>com</groupId>
<artifactId>demo</artifactId>
<packaging>war</packaging>
<name>demo</name>
<version>1.0.0-SNAPSHOT</version>

<dependencies>

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

<!-- Grails defaults to Ehache for the second-level Hibernate cache. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>3.3.1.GA</version>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>1.7.1</version>
<exclusions>
<exclusion>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<artifactId>servlet-api</artifactId>
</exclusion>
<!-- We have JCL-over-SLF4J instead. -->
<exclusion>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- For ease of development and testing, we include the HSQLDB database. -->
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>

<!-- Use Log4J for logging. This artifact also pulls in the Log4J JAR. -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>

<repositories>
<!-- Required to get hold of JTA -->
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
<repository>
<id>Codehaus Snapshots</id>
<url>http://snapshots.repository.codehaus.org</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>Codehaus Snapshots</id>
<url>http://snapshots.repository.codehaus.org</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

<build>
<pluginManagement />
<plugins>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.2.0</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>
<goal>maven-functional-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>tools</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
</project>


Dependency management in Grails 1.2

Graeme Rocher talks about the new DSL-based dependency management system in Grails 1.2, which is due to be released by the end of the month.

Don't know if it will be “done right”, but at least maven users are not forgotten :

If you're addicted to your pom.xml file then we have even added the ability to read dependencies from the pom.xml instead of using the DSL. All in all, Grails 1.2 will give you significantly better control over dependencies and how they are resolved.

Addicted to my pom.xml, that’s right ! ;) Thx Graeme.

Grails 1.1.1 : Maven Integration

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 and add the following sections :
  <plugingroups>
    <plugingroup>org.grails</pluginGroup>
  </pluginGroups>

  <servers />
  <mirrors />
  <proxies />

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