This is a tech post, so that ought to alienate all my readers. But this info isn’t available anywhere on the web (it is on NewNewLondonWork’s wiki, but you can’t see that, and I want something I can refer to later, if needs be.)

Imagine you want to set up a new grails project, have it build with maven (and therefore usable by Hudson) and fiddle with it in intelliJ, and then publish it to your local nexus repository. Well, imagine no more! Here are the simple steps to go through. I couldn’t find this anywhere online, so I went through the pain so you don’t have to. Either that, or all the java people keep this to themselves. Either that, or it is so obvious that I am making myself look dumb. Whatever, here is what needs to be done:

First up, generate the initial bits and bobs from the archetype. This creates a new directory at the level you are sitting. So I recommend you have ~/Projects/ and are in there. YMMV, but YWBW.

mvn
  org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-5:generate 
-DarchetypeGroupId=org.grails 
-DarchetypeArtifactId=grails-maven-archetype 
-DarchetypeVersion=1.3.4 
-DgroupId=com.whatever.you.use
-DartifactId=YourPluginNameHere

I will leave it as an exercise to the reader to change whatever names need changed. I don’t expect your groupId to be my made up one there. You now have a new directory with a pom file, a src/ directory and not much else. But that is alright. That is all you need for now.

OK, as you are going to be publishing your grails plugin (later, hold those horses) to your own lovely nexus repository, change the packaging type in the pom.xml file to be ‘zip’, not ‘jar’. Grails likes its plugins to be zip archives. Whatever. The main project (for me) goes out as a war, but the plugins are all zips. So there.

This next bit is intelliJ specific, as that is what I use. This is also different if you use it on a *ix machine (like me) or a win32/64 box, like not me. Feel free to skip this bit if you need to skip this bit, as it might need skipped.

1. Make sure you have maven home directory set (can be done via File->Settings->Maven)
2. Create a new project
3. Import Grails project from external model (navigate to your plugin directory)
4. Add the framework support for Groovy (there will be a maven 1.3.4 and a local 1.3.4, use the local one)
5. Expand the projects lifecycle node in the maven tab on the right hand side of the screen and compile

This is the part that could (probably) be improved. However, it only takes a few clicks, and once the build process has brought down all the dependencies from nexus, work can be started. There is a chance you might need to add a new SDK, and make it global. This can be found by right-clicking on the plugin name at the top of the project view.

If you use some other IDE, and whatever needed done is done, welcome back. Now we need to make it into a plugin. This is easy. We just add a file called YourPluginNameHereGrailsPlugin.groovy to the root directory of the project. To make that clear, it is the name of the plugin, concated with GrailsPlugin.groovy. But what goes in there, you ask? Here it is:

Class YourPluginNameHereGrailsPlugin {
    def version = "0.1"
    def grailsVersion = "1.3.4 > *"
    def dependsOn = [:]
    def pluginExcludes = [
            "grails-app/views/error.gsp"
    ]
    def author = "mwk"
    def authorEmail = ""
    def title = "Plugging something in"
    def description = "This does stuff"
    def documentation = "http://grails.org/plugin/not-invented-here"
    def doWithWebDescriptor = { xml ->
    }
    def doWithSpring = {
    }
    def doWithDynamicMethods = { ctx ->
    }
    def doWithApplicationContext = { applicationContext ->
    }
    def onChange = { event ->
    }
    def onConfigChange = { event ->
    }
}

Again, that is just ripped off from the standard grails plugin file. Change the class name and whatever else you need to make it reflect you reality.

INSERT YOUR CODE NOW! I have no idea what your plugin is doing, go write the java now. Or do it in groovy, I won’t judge.

Almost there! To allow other developers to use your plugin, you want to push it out to your nexus box. So package the plugin up

grails package-plugin

to create a zip archive in the root directory. The invocation to push this elsewhere is:

mvn deploy:deploy-file 
-DgroupId=com.whatever.you.use.YourPluginNameHere
-DartifactId=YourPluginNameHere
-Dpackaging=zip 
-Dversion=1.0-SNAPSHOT
-Dfile=grails-your-plugin-name-here-0.1.zip 
-DrepositoryId=nexus
-Durl=http://somewhere:8081/nexus/content/repositories/snapshots
-DuniqueVersion=false 
-DarchetypeGroupId=org.grails
-DgroupId=org.grails.plugins 
-Dcompress=true

You will note I have in my m2.settings a repositoryId setup called nexus. I am not going to go in to how you set all that nonsense up, I am presuming you already have one.

All being well, you will see a BUILD SUCCESSFUL message, including the URL to where the zip was pushed.

So now the great unwashed can use your plugin, by adding

plugins.YourPluginNameHere=1.0-SNAPSHOT

to their application.properties file. Job done.

To end with:

Works on my machine

Your normally scheduled (which means months apart) angst will return presently.

Leave the dark corners of the interweb alone. Go to the bright spots shone on by the Beautiful Ones

The BlackStar Diaspora

The wulf insists on text here...and I shall leave it at that.

People I know

I know people who didn't work at BlackStar, and they have weblogs too. These are they.

News, politics and paranoia

The State is not your friend

Mii

It is a well-known fact that the Stray Taoist (nee Toaster) isn't as internally consistent as he thinks he is. Welcome to his world.

Feeds: RSS | Atom