HOW TO BRING DEPENDENCIES UP TO DATE WITH GRADLE

My prior post discussed bringing dependencies up to date with Maven. Here I’ll briefly cover Gradle. I use Gradle in my personal projects, so I looked for some of the features I depended on in Maven and found them missing. In particular, I wanted to keep track of which dependencies where out of date. With Gradle, using open ended patterns for dependency versions is much more the norm, but I still wanted to make sure those patterns were not outdated.

I did some searching, and found a variety of solutions, the closest to mavens versions plugin was a outlined in a a rather dated post from 2011. It offered a starting point at least.

Based on that post, I chose to write my own Gradle plugin. I’ve not done that before so that process was of interest too. I decided to try a Groovy plugin, which is Gradle’s core language. I’m not strong in Groovy but it’s not hard to muddle through if you’re strong in Java.

Goals

My goals were to create a plugin what would:

  • Be simple to use.
  • Understand Gradle’s dependency version patterns.
  • Do a decent job searching the available versions for newer ones.
  • Search all the repositories the build file listed.

VPlugin

Starting with the example of the afore mentioned post I first moved the inline code into an external plugin, and got that into Maven Central. Next I worked to improve the pattern matching, the sorting, and make it use the build files repositories. The result was vplugin and you can find the code there.

Example

Using vplugin

To use this plugin you’ll need to add the following apply:

	apply plugin: 'com.github.nwillc.vplugin'

And modify your build file’s buildscript entry as follows:

	buildscript {
	    repositories {
	           mavenCentral()
		}
		dependencies {
		        classpath 'com.github.nwillc:vplugin:1.+'
		}
	}

Invoking The Plugin’s Task

To invoke the vplugin task simply:

	gradle versions

What You’ll See

This plugin will produce output for your gradle project similar to:

	:versions
	Searching repositories:
		MavenRepo at https://repo1.maven.org/maven2/
		BintrayJCenter at https://jcenter.bintray.com/
		maven at http://maven.tmatesoft.com/content/repositories/releases/
		
	Dependency                                             Using              Update
	----------                                             -----              ------
	com.github.nwillc:almost-functional                    1.6.+ ->            1.7.7
	junit:junit                                             4.11
	org.assertj:assertj-core                               1.7.0
	com.h2database:h2                                    1.4.182
	com.github.nwillc:contracts                            1.6.2

It will show you what your dependency pattern is ends up using, and if the pattern doesn’t match the latest version it will suggest the update version.

Advertisements

One thought on “HOW TO BRING DEPENDENCIES UP TO DATE WITH GRADLE

  1. Pingback: Publishing a Gradle Plugin to plugins.gradle.org | My name is Ozymandias

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