Grails Maven Plugin is still non predictable and it’s 1.0 version supports only 1.1 version of Grails. 1.1-SNAPSHOT version supports grails 1.1.1 but there are still misunderstandings with Grails plugins are exist (Grails wants to store them in your user home, but Grails Maven plugin wants them to be stored in your application dir).
As for now I’m trying to avoid using plugins from Grails, and include all libraries directly with Maven dependencies.
1. Make your maven know where to get grails-maven-plugin by editing your /.m2/settings.xml (create it if there is no one exist):
<settings>
<pluginGroups>
<pluginGroup>org.grails</pluginGroup>
</pluginGroups>
</settings>
2. Go to secret place where you store you projects and run:
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=org.grails -DarchetypeArtifactId=grails-maven-archetype -DarchetypeVersion=1.0 -DgroupId=example -DartifactId=maven-grails-demo
3. Now open just generated pom.xml and make following changes:
-
change versions of grails-crud and grails-gorm from “1.1” to “1.1.1”
-
change grails-maven-plugin version from “1.0” to “1.1-SNAPSHOT”
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.2.3.5521</version>
<scope>runtime</scope>
</dependency>
6. Now, it’s time to import your maven project into Intellij IDEA (I recommend to use latest EAP http://www.jetbrains.net/confluence/display/IDEADEV/Maia+EAP). You can do it by “Create New Project → Import Project from External Model → Maven…”.
Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.groovy.grails.cli.support.GrailsStarter at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:87)
Setting up standalone Grails for your application
- Install Grails as described http://grails.org/Installation.
-
Go to module settings → Groovy → click “Add…” → Create new Grails SDK… → Tell Idea where your standalone Grails is → Click “Replace” (not “Add”, important) in dialog appeared
#1 by craig on September 10th, 2009
Quote
I followed your steps, thank you!, but I noticed IntelliJ is only treating the “src/main/resources” as a “source” directory. It doesn’t point to src/groovy or src/java or grails-app/domain, etc?
did you have to do that manually? I’m using IntelliJ IDEA 9 (build #10666).
#2 by craig on September 10th, 2009
Quote
please hit me up via email craig _at_ grittyapp.org OR on twitter @grittyapp
thanks
#3 by Georgi on September 14th, 2009
Quote
Hi There,
Thanks for this post. I was getting the groovy exception and couldn’t for the life of me figure out why.
I now have a run configuration of mvn: run-app and it works perfectly.
Cheers,
Georgi
#4 by Georgi on September 14th, 2009
Quote
Actually I spoke too soon…. using mvn:run-app seemed to only run a pre-compiled script and not my current changes… im sure this is fixable by putting some sort of mvn target before run-app…
#5 by Alexander Naumenko on September 17th, 2009
Quote
Hm.. strange. “run-app” target running Jetty container which is listens for changes in /target directory and redeploys changes on the fly. What IDE are you using? Anyway, since you’ve made some changes to groovy/java code you should call “Make” to make them be redeployed by Jetty. For *.gsp pages you should just call “Save”.
>>Georgi :
>> Actually I spoke too soon…. using mvn:run-app seemed to only run a
>> pre-compiled script and not my current changes… im sure this is fixable by
>> putting some sort of mvn target before run-app…
#6 by Alexander Naumenko on September 17th, 2009
Quote
Hi Craig,
I’m always creating Intellij IDEA project from external model (maven). It’s smart enough to deal with directory structure defaults overloading in maven pom files. See <a href="http://maven.apache.org/guides/introduction/intro…” target=”_blank”>http://maven.apache.org/guides/introduction/intro… search for “sourceDirectory” inside of “build” section.
Build #10666 is to buggy, so I’m still with 10597. Anyway it could catch all your changes on the fly and mark source/resources directories as expected automagically. If it won’t be so for some reason, try to push “reimport” button in the IDEA’s Maven plugin.
But it won’t work for “grails-app/domain” since IDEA doesn’t understand multiple source directories defined in a pom file. JetGroovy plugin lets us create Grails facets, which recognise Grails dir layout as expected. You could also mark dirs manually, it shouldn’t be broken after next pom reimport.
Hope I covered all you’ve asked,
craig :
>> I followed your steps, thank you!, but I noticed IntelliJ is only treating the
>> “src/main/resources” as a “source” directory. It doesn’t point to src/groovy or
>> src/java or grails-app/domain, etc?
>> did you have to do that manually? I’m using IntelliJ IDEA 9 (build #10666).