Last updated by
3 years ago
Page: Maven Integration, Version:30
The 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.
Also, remove the
Choose whichever group ID and artifact ID you want for your application, but everything else must be as written. This will create a new Maven project with a POM and a couple of other files. What you won't see is anything that looks like a Grails application. So, the next step is to create the project structure that you're used to:
if you see the following message:
edit grails-app/conf/BuildConfig.groovy:19 and uncomment the following line:
call again:
Now we have a Grails application all ready to go. The plugin integrates into the standard build cycle, so you can use the standard Maven phases to build and package your app:
The process will be suspended on startup and listening for a debugger on port 8000.If you need more control of the debugger, this can be specified using the MAVEN_OPTS environment variable, and launch Maven via the default "mvn" command:Execute scripts like this in a Maven environment this way:
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=-Xmx512mYou 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 |