Last updated by 3 years ago
Page: Maven Integration, Version:22
The current Maven plugin is based on, but effectively supercedes, the version created by the guys at Octo who did a great job.
PreparationIn 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!
The Maven 2 integration for Grails has been designed and tested for Maven 2.0.9 and above and will not work with prior version of Maven 2One piece of configuration that may help is setting up a plugin group in your Maven settings file (
Also, remove the
<settings> … <pluginGroups> <pluginGroup>org.grails</pluginGroup> </pluginGroups> </settings>
com.octo.mtgplugin group if you have it set up.
Just do it!Without further ado, let's create our Mavenised Grails project:
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:
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=my-app
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:
mvn package.You can also take advantage of some of the Grails commands that have been wrapped as Maven goals:
Example Usage(first execute archetype as above to create your project)mvn grails:list-pluginsmvn grails:install-plugin -DpluginName=jsecuritymvn initialize
DebuggingMaven can be launched in debug mode using the "mvnDebug" command. To launch your Grails application in debug, simply run:
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:
MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" mvn grails:run-app
Executing scriptsSome 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:
Execute scripts like this in a Maven environment this way:
mvn grails:exec -Dcommand="create-job"
Other versionsDuring 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: