Publishing a Gradle Plugin to plugins.gradle.org

In a prior post I discussed creating a plugin for gradle. The example plugin is useful and so I published it to maven central, and have used it from there.  As I upgraded some of my gradle build files this weekend, I looked into the new plugin mechanism in gradle 2.1+ and checked out what it would take to update my plugin.  It turned out to be easy, just a new publishing mechanism.  The new method to publish adds the plugin to plugins.gradle.org and jcenter, and is easier then the maven central publish for the win!

Here’s What’s Needed

First just follow the steps here to create an account and an API key. Then you update your gradle.properties and your gradle.build. The biggest challenge was incorporating the plugin-publish plugin into the build file. It’s documented here but those notes didn’t cover all I needed to do, so lets look.

First I cleared out the maven central publishing code. Then I added the support for the new plugin. It boiled down to:

// Prepare the artifacts
task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task groovydocJar (type: Jar, dependsOn: groovydoc) {
    classifier = 'groovydoc'
    from groovydoc.destinationDir
}

groovydocJar.dependsOn 'groovydoc'

artifacts {
    archives jar
    archives groovydocJar
    archives sourcesJar
}
// Configure the publish-plugin
pluginBundle {
    website = 'http://nwillc.github.io/vplugin/'
    vcsUrl = 'https://github.com/nwillc/vplugin'
    description = 'Gradle plugin to report newer versions of dependencies'
    tags = ['versions']

    plugins {
        versionsPlugin {
            id = 'com.github.nwillc.vplugin'
            displayName = 'Gradle versions plugin'
        }
    }
}

What the docs did not cover was getting your artifacts prepared (first section above). It’s basic stuff but wasn’t needed before. Once I got that figured out I invoked the publishPlugins task and it worked without issue.

I’ve now switched my other builds to get the versions plugin with the new mechanism and have been very happy with it. As an added perk they generate usage notes for you plugin too!

About the versions plugin.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s