Announcement Announcement Module
No announcement yet.
Working with Mavenized Grails projects in GGTS 3.1.0 *Updated for 3.1.0 release* Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Working with Mavenized Grails projects in GGTS 3.1.0 *Updated for 3.1.0 release*

    EDIT: Rewritten for GGTS 3.1.0. I recommend that you stop using GGTS 3.1.0.M1 for maven integration and move to the latest nightly or the final release. Many fixes are now in.

    GGTS 3.1.0 now has support for mavenized grails projects. This feature requires m2e version 1.1 or later to be installed, which you can find on the dashboard. More information on working with and creating mavenized projects outside of GGTS can be found in the Grails docs.

    Before importing a mavenized grails project, you must make sure of the following in your project and GGTS installation:
    1. Your project uses Grails version 2.1.1 and grails-maven-plugin version 2.1.1 or any later full release. Build snapshots will not work.
    2. You have the same version of Grails unzipped and installed in your GGTS instance.
    3. You have successfully run mvn compile from the command line before importing the project (this ensures that the grails project is in the correct shape and that all plugins are correctly installed and available.
    4. Due to GRAILS-9406, you may need to explicitly add groovy-all 1.8.8 as a dependency. Add this to your dependency section:
    5. You have m2e (Eclipse plugin for maven) v1.1 or later installed in your GGTS.
    6. Your mavenized project uses the grails-app or the grails-plugin packaging. The war packaging will not work since it confuses WTP (Eclipse's Web Tools Project).

    You can import a mavenized grails project using File -> Import... -> Existing Maven project wizard:

    After importing your mavenized project, there may be a dialog asking you to convert the project to a Grails project:

    You should click no. If you click yes, then your project will be imported without the Maven classpath container on it and you will likely have build errors. To get around this problem if you accidentally clicked yes, just run Maven -> Update project.

    Also, your project may have errors if Grails dependency management has not been enabled. You can manually turn on Grails dependency management like this:

    Once Grails dependency management has been enabled, you will notice that your mavenized project will have classpath containers both for Grails and for Maven:

    This is OK. In GGTS, mavenized grails projects are treated using a hybrid of Grails and Maven features, and so grails-ide and m2e share responsibility to manage dependencies and provide functionality. It shouldn't be a surprise that, interacting with these kinds of projects will be different than interacting with a pure grails project.

    First, here is a list of functionality known to work the same as before:
    • Editor support, Groovy search, GSP search, Groovy refactoring and other editing commands
    • The Project explorer view will show your project in a Grailsy way
    • Grails commands that only manipulate project files such as create-domain-class, generate-views. You can execute these commands in any of the normal ways: the lightweight grails pop-up dialog, the grails command wizard, or a custom grails launch.
    • Grails run-app and test-app will work as before including all debugging support

    And there are some parts of your project that must be interacted with differently:
    • Refresh dependencies/Project update: Don’t run Grails -> Refresh dependencies to update your classpath. Instead, run Maven -> Update project. Running refresh dependencies is disabled for mavenized projects since Maven manages the classpath.
    • Installing plugins: you can open the Grails plugin manager, but you can’t install plugins from there. Instead, install plugins by adding the dependency to the plugin in your pom. Then run Maven -> Update project.
    • Uninstalling/upgrading plugins: If you are uninstalling or upgrading a plugin:
      1. First update your pom.xml to reflect the new dependencies
      2. Run mvn clean on the project. This can be done either on the command line or inside of GGTS
      3. Run Maven -> Update project inside of GGTS.
      This will give you a clean compile using the new plugins and removing any old ones.
    • [B]Forked mode[B]: Note that GGTS will automatically run your Grails goals in forked mode even if you have explicit configuration in your pom otherwise. This is to avoid running out of permgen when Grails is run in-process.

    If you have any problems or comments, please reply to this post. Also, be aware that most of the comments on the first page are outdated since they deal with an older version of these instructions.

    Suggestions to improve these instructions are appreciated!
    Attached Files
    Last edited by Andrew Eisenberg; Oct 4th, 2012, 04:03 PM. Reason: Update for 3.1.0 release

  • #2
    Where can I find the "Maven -> Update project" menu? I don't see it in any of the regular menus or toolbars.


    • #3
      First you need to install m2e. As described above, Go to Help -> Install new software. In the "Work with" box, choose the Juno update site. Look for the m2e entries and install them.


      • #4
        m2e is already installed (btw I'm running GGTS 3.0.0). so, with m2e installed, where is the Maven menu/button?


        • #5
          Right click on the project in the project or package explorer. There should be a 'Maven' menu.

          If the menu is not there, it could be that your project doesn't have 'Maven nature'. Only projects with maven nature will have m2e functionality, such as the 'Maven' menu.

          To add maven nature, use "Configure >> Convert to Maven Project".


          • #6
            ah yes - the context menu - thanks for the reminder!


            • #7
              WTP integration incompatibility?

              Originally posted by Andrew Eisenberg View Post
              Do NOT install from the dashboard, since that will also install WTP integration which will confuse m2e into converting the project into a WTP project.
              I'm curious to know why. I happen to know a thing or two about the WTP integration and, given that Grails projects have the grails-app packaging, I'm pretty sure they're completely ignored by m2e-wtp (which only messes with war, ejb, ear, rar, app-client packagings).




              • #8
                The grails-app packaging is optional and a fairly recent addition to the grails-maven integration. Moreover, the archetype for Grails 2.1.1 still produces a pom that uses a war packaging type (it can be changed, but it is not easy to figure out unless you are already familiar with the grails-maven-plugin). So, if you have WTP integration installed, then a grails project that doesn't use grails-app packaging will be treated incorrectly in GGTS. (There might be a way to create a custom lifecycle mapping to fix this to ignore the WTP maven plugins, but it's just simpler to say not to use it.)

                This all has been fixed in the latest snapshot and the 3.1.0.RC1 build out this week. We have updated the grails-maven archetype to use the grails-app packaging and GGTS now correctly recognizes the packaging. When RC1 is out, I will fix up this documentation to reflect the changes.

                So, I'm not really sure if this is a WTP problem or a Grails problem. It would certainly be nice if WTP maven integration did not trample on war packaged mavenized grails apps, but I'm hoping that this packaging style will be deprecated. The instructions for using this in 3.1.0.RC1 and later will be vastly simplified and part of ensuring this is by being clear as to exactly what we do and do not support.


                • #9
                  Here is some additional steps required to get this working. I used the GGTS M1 release - not nightly build, windows 7, java 7, and the GGTS installed version of maven.

                  1. When you install GGTS, before you do anything else, specify your JDK in your IDE settings rather than the default JRE. While I eventually did this, the maven $java.home variable was stuck with the JRE for sometime causing a dependency error for the POM in m2e view.

                  1.1. I still had issues even after doing this so I had to create a shortcut for GGTS and add a vm parameter after GGTS in the short cut. Here is an example of mine:

                  GGTS.exe -vm "C:\development\Java\jdk1.7.0_07\bin"

                  2. When you do the "import existing maven project" step, GGTS will ask you if you wish to convert this to a grails project. Select yes to all. It might be obvious to some, but after trying this a number of times I was beginning to question if this was one of the issues. It isn't.

                  3. For m2e it is prudent to enable to enable reindex on start from > windows>preferences>maven

                  ...and restart GGTS.

                  4. Totally frustrating was the fact that maven dependencies was still not working. Add the following to the .classpath of the project:

                  <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>

                  5. The maven package command works but on deployment it also includes the latest servlet jar which will cause a conflict with most/all web servers. Adding an excludes directive to the POM solves this i.e.


                  6. So everything should now work. I STILL have an issue albeit none critical: the project reports over 100 grails dependency problems see screen shot below. Its not critical but really annoying - any ideas?


                  • #10
                    Thanks for the extra suggestions.

                    I STILL have an issue albeit none critical: the project reports over 100 grails dependency problems see screen shot below. Its not critical but really annoying - any ideas?
                    I'm guessing that the problem here is that Grails-IDE is adding source locations for plugins in your ~/.grails folder, when they don't exist there (maven puts them inside the project). This will happen because of what you did in step #2. Running Grails refresh dependencies will cause this. For now, the best fix is to delete your project from the workspace, run mvn eclipse:clean on the command line and re-import.

                    That being said, this and many other issues have been fixed for our RC1 release. I'll be updating the docs in the next day or so with new (and simpler) instructions.


                    • #11
                      Enabling Grails Dependency Management

                      I'm confused about how to enable Grails dependency management 'manually'.

                      When importing the project as an existing maven project, I am asked if I want to convert the project to a Grails project. Am I supposed to select 'No to all'? I selected 'No' because the instructions posted said nothing about this dialog and how one should respond to it.

                      After importing the project, I couldn't find anything about how to enable Grails dependency. Am I supposed to right click on the project and select 'Convert to grails project'? I did that and the project is then converted. However, when I expand the classpath item, I only see Grails dependencies, not both Maven and Grails. The Maven item is still on the context menu when I right click on my project though.
                      Last edited by selenareneephillips; Oct 4th, 2012, 11:27 AM.


                      • #12
                        I just did a complete refresh of the instructions for the 3.1.0 release out next week (you can also update to a nightly snapshot to get it now). I would recommend that you update and try again using the new instructions. Should be much more straight forward now.

                        Let me know if this helps anything.


                        • #13
                          That worked

                          That worked.

                          I am getting this warning:

                          Build path specifies execution environment JavaSE-1.6. There are no JREs installed in the workspace that are strictly compatible with this environment.

                          I added the maven-compiler-plugin to my pom and specified the source and target to be java 1.7. I have installed the oracle java 7 JDK and added it as an execution environment in my Java Preferences. So, I don't understand how or why m2e is setting the execution environment to Java 1.6 for my project.
                          Last edited by selenareneephillips; Oct 4th, 2012, 07:53 PM.


                          • #14
                            Have a look at Project -> Properties -> Java Build Path -> Libraries. Your JRE System Library, what level is it at? I'm guessing that this is where the incompatible execution environment is coming from.


                            • #15
                              It has Java SE 1.6. However, in my pom.xml I have specified this for the maven-compiler plugin:


                              This should tell maven to use java 1.7. I have installed oracle java 7 and configured GGTS Preferences>Intalled JREs to point at that. Yet, somehow, m2eclipse always sets the project properties to Java SE 1.6 after I run Maven>Update Project. I don't know where it is getting this setting. Nothing in my pom or anything in GGTS is telling it to use 1.6.