0

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!

Brun0
  • 1
  • 3
  • Please add the code you have tried and how it failed (e.g. errors, stacktraces, logs, ...) so we can improve on it. – cfrick Jul 31 '21 at 07:32
  • First I saw it correct on the grails site version 4.0.X is the current one? So why using an older version of Grails...And why do you need to do the work with Maven? – khmarbaise Jul 31 '21 at 11:20
  • Hi, @khmarbaise, I was asked to add Maven to this project, not much choice in the matter :) – Brun0 Jul 31 '21 at 17:28
  • "First I saw it correct on the grails site version 4.0.X is the current one?" - 4.0.11 is our latest GA release. 5.0 is not out yet but we have released 5.0.0.M2. – Jeff Scott Brown Aug 02 '21 at 13:21

1 Answers1

0

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>
Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47
Skod
  • 435
  • 6
  • 16
  • Thanks a lot, @skod! :) I've added the plugin but I'm facing the errors I updated the original question with. – Brun0 Jul 31 '21 at 17:30
  • It looks like your compiler can't find Hibernate classes. Is there a reason your hibernate plugin was declared in `runtime` scope? I'm sure you are aware that those dependencies are excluded from the classpath during compilation. Do you mind using the default scope? – Skod Jul 31 '21 at 19:32
  • Thanks again, I did change the scope but the Hibernate error persists. It seems I have conflicting dependencies (like it's mentioned here https://stackoverflow.com/questions/8799121/java-lang-nosuchmethoderror-org-hibernate-sessionfactory-opensessionlorg-hibe). Changing Hibernate's version did make the error go away, but other problems appeared. Still your answer was correct, so I'll mark it as such. – Brun0 Aug 02 '21 at 14:46