Add Maven to a Grails project

452 Views Asked by At

first question here :)

I have a Grails project (using version 2.5.6) and instead of using grails to generate the war file, like I'm doing now, I need to compile the project with Maven.

I was wondering if anyone here had ever implemented Maven on a Grails project and knew what the steps would be to correctly add all the dependencies.

EDIT

I've already created the pom file and added the grails-maven-plugin. But when I try to run mvn grails:run app for example, it fails to compile:


    |Compiling 174 source files
      [groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      [groovyc] Compile error during compilation with javac.
      [groovyc] C:\...\plugins\webflow-2.0.8.1\src\groovy\org\codehaus\groovy\grails\webflow\persistence\FlowAwareCurrentSessionContext.java:18: error: cannot find symbol
      [groovyc] import org.hibernate.classic.Session;
      [groovyc]                             ^
      [groovyc]   symbol:   class Session
      [groovyc]   location: package org.hibernate.classic
      [groovyc] C:\...\plugins\webflow-2.0.8.1\src\groovy\org\codehaus\groovy\grails\webflow\persistence\FlowAwareCurrentSessionContext.java:19: error: cannot find symbol
      [groovyc] import org.hibernate.engine.SessionFactoryImplementor;
      [groovyc]                            ^
      [groovyc]   symbol:   class SessionFactoryImplementor
      [groovyc]   location: package org.hibernate.engine
      [groovyc] C:\...\plugins\webflow-2.0.8.1\src\groovy\org\codehaus\groovy\grails\webflow\persistence\FlowAwareCurrentSessionContext.java:34: error: cannot access CurrentSessionContext
      [groovyc] public class FlowAwareCurrentSessionContext extends SpringSessionContext {
      [groovyc]        ^
      [groovyc]   class file for org.hibernate.context.CurrentSessionContext not found...

Both Webflow and Hibernate dependencies are declared in my pom file though:

<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>webflow</artifactId>
    <version>2.0.8.1</version>
    <scope>compile</scope>

    <type>zip</type>

</dependency>
    
<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>hibernate</artifactId>
    <version>2.2.1</version>
    <scope>runtime</scope>

    <type>zip</type>

</dependency>

PD: I'm behind a proxy downloading the dependencies from Nexus.

Thank you!

1

There are 1 best solutions below

3
On

What we've used on a previous project was grails-maven-plugin which provides support for grails commands as maven goals (our grails version was 2.3.11 so I assume it's compatible with yours)

You can generate a normal pom.xml file on your project, keep the grails structure and also build your project through maven. The plugin should be added in the <plugins> section of your pom file:

<build>
    <plugins>
        <plugin>
            <groupId>org.grails</groupId>
            <artifactId>grails-maven-plugin</artifactId>
            <version>2.4.6</version>
            <configuration>
                <grailsVersion>${grails.version}</grailsVersion>
                ....
            </configuration>
            <extensions>true</extensions>
            <executions>
                <execution>
                    ....
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>