Monday, January 4, 2010

Grails Plugins With In-House Repository Part 2.

In part one we covered setting up the subversion repository.  In this post we are going to look at how to configure your plugin project to publish to your repository, and how to configure your projects to use plugins from this repository. 

In your plugin project you will need to add a new file BuildConfig.groovy under grails-app/conf.
As you probably guessed from the name, this file is used to customize the behavior of the grails build system.  Among other things this file allows you to get dependencies from maven /ivy repositories (grails 1.2 only), use plugin repositories, and change the base directories for your plugins.
You need to add a couple of lines to this file to tell grails where to publish the plugin, and resolve other plugins.  



grails.plugin.repos.discovery.myRepository="http://url-to-repository.com"
grails.plugin.repos.distribution.myRepository="http://url-to-repository.com"

If you are using authentication on your repository, and you do not wish to be prompted every time you build you can include the username and password as part of your url.
Note grails assumes you are using authentication if you are using https as your protocol.

grails.plugin.repos.discovery.myRepository="https://username:password@url-to-repository.com"
grails.plugin.repos.distribution.myRepository="https://username:password@url-to-repository.com"

I recommend using the BuildConfig.groovy file as it makes your build more portable. However you can also set this information for all projects using the USER_HOME/.grails/settings.groovy

Now that you have configured your plugin, you can publish it to the repository using the grails release-plugin command.  You have to provide an argument of what repository to use.

grails release-plugin -repository=myRepository 

Tip: Due to a bug in grails, if you are using windows you have to add quotes around your arguments grails release-plugin "-repository=myRepository"

When you run this command grails will import your plugin into subversion with the following structure.
  • /.plugin-meta/plugins-list.xml (This file is updated each time you release a new version of a plugin it) 
  • /grails-/tags/LATEST_RELEASE (This is automatically updated everytime you release) 
  • /grails-/tags/ (This is used to resolve specific versions of your plugin) 
  • /grails-/trunk/ (This is the latest working copy.  You should check this out to make changes to your plugin)  

Finally you need to add a BuildConfig.groovy file to your projects where you wish to use this plugin. This file needs to contain the discovery url for your plugin repository.

grails.plugin.repos.discovery.myRepository="http://url-to-repository.com"
You will now be able to use the list-plugins and install-plugin commands on your in-house repository.

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi Keith,

    Thanks for sharing a great post.

    Just curious do you have success experience using Assembla SVN (http://www.assembla.com/) as own Grails plugins repository?

    I managed to publish the plugin to the Assembla SVN repo but facing problem in plugin discovery phase such as install-plugin command.

    I had tried configure BuildConfig.groovy like the following code:
    repositories {
    grailsRepo "https://subversion.assembla.com/svn/myrepos/grails-plugins"
    grailsPlugins()
    ....
    }

    Creating settings.groovy in .grails directory:
    grails.project.ivy.authentication = {
    credentials {
    host = "subversion.assembla.com"
    username = "mylogin"
    password = "mypassword"
    }
    }

    Even tried configured this in BuildConfig.groovy:
    grails.plugin.repos.discovery.myPluginRepository="https://mylogin:mypassword@subversion.assembla.com/svn/myrepos/grails-plugins"

    But none of the above is working, any idea? Please advice.

    Regards,
    Chee Kin

    ReplyDelete
  3. Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good. Avenue South Residence Core City Centre

    ReplyDelete