Continuous Delivery, Java to Heroku via Travis CI

I’ve been using the heroku app Maven-Badges to show the latest release of my projects for some time. I like it, but as I started to use JCenter, and Gradle Plugins to release projects I was looking for similar tools for those. I didn’t find anything that was a good fit. Maven badges is written in Ruby, and my ruby skills are basic, so offering to enhance that didn’t seem like the way to go. So, having never used Heroku, I took it as an opportunity to learn something new, and decided to write one.

Objectives

First I laid out my objectives:

  • Keep it simple and light weight
  • Make it extensible and easy to maintain
  • Initially support: maven central, jcenter, gradle plugins
  • Try out one of the micro RESTful frameworks for Java
  • Deploy it to Heroku

How it All Came Together In a Couple of Days

After a quick first days iteration, I landed on a tool chain I am pleased and impressed with.

  • Java 8.
  • JUnit and Mackito for testing.
  • Spark Framework for the RESTful server.
  • Gradle as the build tool.
  • Github as the source repository
  • Travis CI for continous integration and deployment.
  • Jacoco and Coveralls for code coverage.
  • Heroku for app hosting.

So basically, I coded a really simple little service in Java and Spark, using Gradle to build it. The source is on Github. When I push to Github, Travis picks it up, builds it, and runs my tests, and has Coveralls deal with the code coverage. If the tests and coverage are clean, Travis deploys a release on Heroku. None of this is original, all I did was cobble together various clear examples. No muss. No fuss. All automated. Pretty damn slick.

Resources

I’m not going to walk through many of the details, because as I said, mostly I just cobbled together other examples. You can look at my results in Github or target the repo-redirect app directly.

About the only bits of unique work I ended up doing was figuring out how to implement the gradle stage task that Heroku uses to deploy a gradle based project. I took a dead simple approach adding the following to my build.gradle:

task stage(type: Copy) {
    from sourceSets.main.runtimeClasspath
    into 'build/dependency'
}

stage.dependsOn build

What that did for me was have gradle stage first build the project and then collect all the dependencies into build/dependency. With that done, Heroku’s Procfile could read as:

web: java -cp build/dependency:build/dependency/* com.github.nwillc.shields.Shields --port $PORT

All the other info you’ll need can be found as follows:

Advertisements

2 thoughts on “Continuous Delivery, Java to Heroku via Travis CI

  1. Pingback: OpenShift, JDK 8, Gradle 2.3, Working Together | My name is Ozymandias
  2. Pingback: Your Existing Github to OpenShift With Travis-CI | 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