This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

Working with Mavenized Grails projects in GGTS 3.1.0 *Updated for 3.1.0 release*Page Title Module

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

Sep 11th, 2012, 04:11 PM

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:

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.

You have the same version of Grails unzipped and installed in your GGTS instance.

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.

Due to GRAILS-9406, you may need to explicitly add groovy-all 1.8.8 as a dependency. Add this to your dependency section:

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

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:Attachment

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

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:

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:

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:

First update your pom.xml to reflect the new dependencies

Run mvn clean on the project. This can be done either on the command line or inside of GGTS

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.

Comment

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

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.

Comment

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:

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?

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.

Comment

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.

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.

Comment

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.

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.

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.