## 12.2 Plugin Repositories

#### Distributing Plugins in the Grails Central Plugins Repository

The preferred way of plugin distribution is to publish your under Grails Plugins Repository. This will make your plugin visible to the list-plugins command:

    grails list-plugins

Which lists all plugins in the Grails Plugin repository and also the plugin-info command:

    grails plugin-info [plugin-name]

Which outputs more information based on the meta info entered into the plug-in descriptor.

> If you have created a Grails plugin and want it to be hosted in the central repository take a look at the wiki page , which details how to go about releasing your plugin in the repository.

When you have access to the Grails Plugin repository to release your plugin you simply have to execute the release-plugin command:

    grails release-plugin

This will automatically commit changes to SVN, do some tagging and make your changes available via the list-plugins command.

#### Configuring Additional Repositories

The way in which you configure repositories in Grails differs between Grails versions. For version of Grails 1.2 and earlier please refer to the Grails 1.2 documentation on the subject. The following sections cover Grails 1.3 and above.

Grails 1.3 and above use Ivy under the hood to resolve plugin dependencies. The mechanism for defining additional plugin repositories is largely the same as defining repositories for JAR dependencies. For example you can define a remote Maven repository that contains Grails plugins using the following syntax in `grails-app/conf/BuildConfig.groovy`:

    repositories {
    	mavenRepo "http://repository.codehaus.org"
    }

You can also define a SVN-based Grails repository (such as the one hosted at http://plugins.grails.org/) using the `grailsRepo` method:

    repositories {
    	grailsRepo "http://myserver/mygrailsrepo"
    }

There is a shortcut to setup the Grails central repository:

    repositories {
    	grailsCentral()
    }

The order in which plugins are resolved is based on the ordering of the repositories. So for example in this case the Grails central repository will be searched last:

    repositories {
    	grailsRepo "http://myserver/mygrailsrepo"
    	grailsCentral()
    }

All of the above examples use HTTP, however you can specify any Ivy resolver to resolve plugins with. Below is an example that uses an SSH resolver:

    def sshResolver = new SshResolver(user:"myuser", host:"myhost.com")
    sshResolver.addArtifactPattern("/path/to/repo/grails-[artifact]/tags/LATEST_RELEASE/grails-[artifact]-[revision].[ext]")
    sshResolver.latestStrategy = new org.apache.ivy.plugins.latest.LatestTimeStrategy()
    sshResolver.changingPattern = ".*SNAPSHOT"
    sshResolver.setCheckmodified(true)

The above example defines an artifact pattern which tells Ivy how to resolve a plugin zip file. For a more detailed explanation on Ivy patterns see the relevant section in the Ivy user guide.

#### Publishing to Maven Compatible Repositories

In general it is recommended for Grails 1.3 and above to use standard Maven-style repositories to self host plugins. The benefits of doing so include the ability for existing tooling and repository managers to interpret the structure of a Maven repository. In addition Maven compatible repositories are not tied to SVN as Grails repositories are.

In order to publish a plugin to a Maven repository you need to use the Maven publisher plugin. Please refer to the section of the Maven deployment user guide on the subject.

#### Publishing to Grails Compatible Repositories

To publish a Grails plugin to a Grails compatible repository you specify the `grails.plugin.repos.distribution.myRepository` setting within the grails-app/conf/BuildConfig.groovy file:

    grails.plugin.repos.distribution.myRepository="https://svn.codehaus.org/grails/trunk/grails-test-plugin-repo"

You can also provide this settings in the USER_HOME/.grails/settings.groovy file if you prefer to share the same settings across multiple projects.

Once this is done you need to use the `repository` argument of the `release-plugin` command to specify the repository you want to release the plugin into:

    grails release-plugin -repository=myRepository