How to publish your Grails 3 plugin to Bintray


With Grails 3 now available, we have started to migrate some of our Grails 2 plugins. Here is a quick guide to share your experience on how to distribute a Grails 3 Plugin. Feedback is welcome!

To migrate your plugins and apps, follow the detailed explanation from Grails 3 docs: http://grails.github.io/grails-doc/3.1.x/guide/upgrading.html

You might also check this Grails 2 plugin that automatically performs a partial migration: https://github.com/domurtag/migrate-2-grails3

To distribute your plugins, the recommended way is to use Bintray, a package hosting and download center infrastructure for automated software distribution. It’s free for open source!

On the Bintray side

  • signup/signin to https://bintray.com (one-click signin with GitHub or Twitter),
  • if required, create an organization (if you want to collaborate on a shared repository),
  • create a new maven repository called plugins on your account (or the created organization),
  • edit your Bintray profile to get your personal API Key,
  • add BINTRAY_USER and BINTRAY_KEY to your env variables (on OS X, add it to your .bash_profile or .bash_rc)
export BINTRAY_USER=benorama
export BINTRAY_KEY=xxxxxxxxxxxxxxxxxx

On the Grails side (Grails 3.1 and beyond)

  • run grails create-plugin my-plugin,
  • from Grails 3.1.x, there is new Gradle plugins available to simplify publishing of plugins and profiles. It should be in your build.gradle when you create a new plugin.
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-plugin-publish"
  • edit build.gradle to customize default configuration as you wish , for example:
grailsPublish {
user = 'user' // Not required if you defined BINTRAY_USER var
key = 'key' // Not required if you defined BINTRAY_KEY var
userOrg = 'mycompany' // Optional
repo = 'myrepo' // Optional, default to 'plugins'
githubSlug = 'foo/bar'
license {
name = 'Apache-2.0'
}
title = "My Plugin Title"
desc = "My Plugin Description"
developers = [johndoe:"John Doe"]
}

On the Grails side (Grails 3.0.x)

// Replace benorama by your github user/organization name
// Note: right now, only plugins with 'org.grails.plugins' group are listed by 'grails list-plugins' command
version "0.1"
group "org.grails.plugins" // Or your own user/organization
bintray {
pkg {
userOrg = '' // If you want to publish to an organization
name = "$project.name"
issueTrackerUrl = "https://github.com/benorama/grails-$project.name/issues"
vcsUrl = "https://github.com/benorama/grails-$project.name"
version {
attributes = ['grails-plugin': "$project.group:$project.name"]
name = project.version
}
}
}

To publish your Grails 3 plugin

  • now, simply run gradle bintrayUpload from your project root.
Et voila !
Your first Grails 3 plugin is published and available to everyone.

Note: if you want to add your plugin to the official plugins repository, go to https://bintray.com/grails/plugins, click on Include my package button and wait for Grails team validation.

To use your Grails 3 plugin

Add your plugins repo and plugin dependency to your Grails 3 app in its build.gradle :

// Replace benorama by your user/organization name
repositories {
...
maven { url "http://dl.bintray.com/benorama/plugins" }
}
dependencies {
...
compile "org.grails.plugins:my-plugin:0.1"
}

FAQ

Bobby Warner has created a nice FAQ blog post about Publishing Grails 3 Plugins.


Note: we’re hiring! Are you kick-ass fullstack or front-end dev that want to work on Angular 2, Java or Groovy? You must contact me to join our dream team in Paris!

If you liked this article, please hit the ❤ button to recommend it. This will make it easier for other Medium users to discover this.

Show your support

Clapping shows how much you appreciated Benoit Hediard’s story.