2.3. Updating the DOM Project

The dom project is the place where the bulk of your domain objects live. Since these are now written in Groovy, we need to ensure that they are compiled.

2.3.1. Source folders

First off, we must separate our Groovy code from any Java code. To do this, create the following folders:

  • src/main/groovy

  • src/test/groovy

It's important to create both of these folders (even if you aren't planning on writing any unit tests ;-) ... the IDE integration that we describe below insists upon it.

2.3.2. Updating the Maven POMs

First, we update the POM our domain objects are compiled using the Groovy compiler. Add the following into <build>:

<build>
    <plugins>

        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
        </plugin>

    </plugins>
</build>

Next, we add dependencies both to Groovy Objects' own applib and to Groovy itself:

<dependencies>
    ...

    <dependency>
        <groupId>org.starobjects.groovy</groupId>
        <artifactId>gapplib</artifactId>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
    </dependency>

</dependencies>

The Groovy Objects applib brings in a transitive dependency to the Naked Objects applib along one or two helper classes (of which more in Chapter 4, Writing Fixtures in Groovy). In the future the applib may be expanded to include other helper classes or new annotations provided by Groovy Objects itself.

Finally, a small workaround. Naked Objects picks up icons for domain classes from the classpath, with the Java compiler doing the job of copying these icons from src/main/resources into target. The Groovy compiler does not seem to do this. We therefore ensure that the Java compiler runs by adding a small dummy Java class. It could go anywhere, but the images package is probably the best location:

package images;

/**
 * workaround to force Java compiler to kick in and copy images over to target classpath
 */
class Dummy {}

At this point you should be able to build your project from the Maven command line. Let's see how to add in IDE support.

2.3.3. Configuring Eclipse IDE

If you are using Eclipse IDE, then you can add in Groovy support using the GroovyEclipse plugin.

To start off with, install the plugin into your IDE using the standard Eclipse update mechanisms. There's a detailed walkthrough on the Groovy wiki if you need it.

Next, enable the Groovy nature in your dom project:

Doing this brings in Groovy editor and compiler support (technically: the Groovy nature is added to the project). But it also adds in a reference to the Groovy runtime to our classpath, which we don't need because we already have courtesy of Maven. Therefore, remove the Groovy Libraries classpath library:

And that should do the trick.

2.3.4. Other IDEs

If you use another IDE, please let us know what the steps are to configure it, and we'll update this documentation.