Last updated by pledbrook
2 years ago
This page is deprecated. You should refer to section 4.5 of the user guideThe current Maven plugin is based on, but effectively supercedes, the version created by the guys at Octo who did a great job. Until this page is updated, you'll still want to use the documenation over at octo.
Preparation
The Maven 2 integration for Grails has been designed and tested for Maven 2.0.9 and above and will not work with prior versions of Maven 2In order to try the new plugin, all you need is Maven 2 installed and set up. In fact, you should unset the GRAILS_HOME environment variable when running Maven with a Grails project. This is because you no longer need to install Grails separately to use it with Maven!
If you are running grails 1.2-M3, you must set GRAILS_HOME due to GRAILS-5220 (Fixed in Grails 1.2-M4)One piece of configuration that may help is setting up a plugin group in your Maven settings file (
$HOME/.m2/settings.xml ):
<settings> … <pluginGroups> <pluginGroup>org.grails</pluginGroup> </pluginGroups> </settings>
com.octo.mtg plugin group if you have it set up.Just do it!
Without further ado, let's create our Mavenised Grails project:mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate \
-DarchetypeGroupId=org.grails \
-DarchetypeArtifactId=grails-maven-archetype \
-DarchetypeVersion=1.2.0 \
-DgroupId=example -DartifactId=my-appmvn initialize
:::::::::::::::::::::::::::::::::::::::::::::: :: UNRESOLVED DEPENDENCIES :: :::::::::::::::::::::::::::::::::::::::::::::: :: org.hibernate#hibernate-commons-annotations;3.3.0.ga: not found :: javassist#javassist;3.8.0.GA: not found ::::::::::::::::::::::::::::::::::::::::::::::
mavenCentral()
mvn initialize
mvn clean , mvn compile , mvn test , mvn package .The default mvn setup DOES NOT supply sufficient memory to run the Grails environment. We recommend that you add the following environment variable setting to prevent poor performance:export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=192m"You can also take advantage of some of the Grails commands that have been wrapped as Maven goals:
- grails:console
- grails:create-controller
- grails:create-domain-class
- grails:create-integration-test
- grails:create-pom
- grails:create-script
- grails:create-service
- grails:create-tag-lib
- grails:create-unit-test
- grails:exec
- grails:generate-all
- grails:generate-controller
- grails:generate-views
- grails:install-plugin
- grails:install-templates
- grails:list-plugins
- grails:package
- grails:run-app
- grails:run-app-https
- grails:uninstall-plugin
application.properties :
plugins.hibernate=1.2.0
Example Usage
(first execute archetype as above to create your project)mvn grails:list-pluginsmvn grails:install-plugin -DpluginName=jsecuritymvn initializeDebugging
Maven can be launched in debug mode using the "mvnDebug" command. To launch your Grails application in debug, simply run:mvnDebug grails:run-app
MAVEN_OPTS="-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" mvn grails:run-appExecuting scripts
Some plugins have extra scripts for generating config files or other artifacts. For instance, the Quartz plugin has a create-job script which is invoked in a non-Maven environment via:grails create-job
mvn grails:exec -Dcommand="create-job"Other versions
During the beta and RC cycles, several versions of the plugin and archetype are released. Here's a table of the versions you need to use for a given version of Grails:| Grails | Plugin | Archetype |
|---|---|---|
| 1.1-beta1 | - | - |
| 1.1-beta2 | 0.4 | 1.0-beta2 |
| 1.1-beta3 | 1.0-beta3 | 1.0-beta3 |
| 1.1-RC1 | 1.0-RC1 | 1.0-RC1 |
| 1.1-RC2 | 1.0-RC2 | 1.0-RC2 |
| 1.1-SNAPSHOT | 1.0-SNAPSHOT | 1.0-SNAPSHOT |
| 1.1 | 1.0 | 1.0 |
| 1.1.1 | 1.1 | 1.1 |
| 1.2.0 | 1.2.0 | 1.2.0 |
| 1.2.1 | 1.2.1 | 1.2.1 |
| 1.2.2 | 1.2.2 | 1.2.2 |