Gradle Example with Spring 3, Hibernate, Scaml, and Bootstrap

I’ve been focused on Gradle, and the one thing I think the Gradle community needs more of is a set of “real” examples.  While the Gradle distribution has a handful of simple examples, these don’t resemble the applications we’re building in the real-world (i.e. web applications that babysit databases, etc.).

Now, here’s the problem, when you talk to expert Gradalians (or Gradlists which one is it?), they want to demonstrate the most complex use cases, the use cases that can beat the competition.    These would be builds with often esoteric edge-case dependency issues or builds that demonstrate integration with tools like Sonar without having to drag along an encyclopedia of XML configuration.  These are valuable examples, but the majority of us “regular folk” just want to see a straightforward example using a set of technologies we use every day.

That’s what this project is all about.  This is the first in a series of sample applications designed to demonstrate Gradle in the context of other technologies.  In these applications I’m not interested in rigging up some fantastic Gradle use case (although, that will eventually happen).   My aim is to introduce you to Gradle by way of other technologies.  Along these lines, I’ve created a sample web application that babysits a database using the following technologies:

  • Spring Data and Spring JPA – Spring Data and Spring JPA with Hibernate implementing the JPA side of things.  Oliver Gierke has done some great work demonstrating Spring JPA, and if you are looking to get started with Spring JPA, this application is also a great place to start.   This application uses a simple CrudRepository to implement two simple JPA repositories.
  • Spring MVC – This web application is annotation driven and it also demonstrates the use of a model attribute to simplify form processing.  If you haven’t looked at some of the new features of Spring MVC in a while take a look at this sample application.
  • Scaml – Scaml is a subproject of Scalate.   In Ruby on Rails, I’m a big fan of Haml.  Haml’s terse syntax saves me from having to do battle with ugly HTML templates, and Scaml uses Scala to bring a similar approach to this application.   If you haven’t looked at Haml or Scaml yet, check out this application.
  • Bootstrap – Wondering how to integrate Bootstrap CSS and JS with Scaml-based views and a custom task in a Gradle build which downloads Bootstrap as a dependency?   This application was made for you.
  • Gradle – This sample application started out as an excuse to demonstrate Gradle.   I’m not going out of my way to demonstrate specific features of Gradle, I’m simply trying to demonstrate how Gradle can be used to build fairly complex projects without all the build configuration hell I’ve grown accustomed to.

The idea here is that you’ll be able to clone this repository or simply copy and paste the code to get started on a real application.  If one of these sample applications is published once a week for the next year, the Gradle community ends up with a variety of examples each providing another piece of the puzzle.   Will they all adhere to best practices of Gradle?  Probably not.   Will they all be this straightforward?  Probably not.  Will they all be Spring-based web applications?  No.

Clone the Sample Application

Here is it:

Go clone it, and note that I’m still developing it.   I’m using this simple consolidated application as a base for future work to develop this into a full example.

Build and Run It

Once you’ve cloned the repository, change directories into the project directory and run:

gradlew jettyRun

That’s it.   The Gradle Wrapper will take care of downloading Gradle if you don’t have it.  That should result in Jetty listening on http://localhost:9090/blog-example/.   Load http://localhost:9090/blog-example/users/sign-up and then load http://localhost:9090/blog-example/users/all

Don’t get too excited just yet, this application doesn’t implement the basics of a blog just yet. (I’m working on it.)  This semi-functional application is using an in-memory HSQL database so the user you create will be destroyed when you stop Jetty, but functionality isn’t the point of this sample application.  The point is for you to open up an IDE and take a look at the source.

More to Come

I’ll be writing more about the custom Gradle tasks in this project and other parts of this application, but this is the first in a long series.   Many of you are taking a look at Gradle, and quite a few of you have asked for more concrete examples…. so here they come.

Oh, and BTW, register for the Gradle Summit 2013

I’m giving a talk at the Gradle Summit on some of the applications.  Come out to Santa Clara for the week.  Gradle Summit is the world’s first conference for the award-winning Gradle open source build automation tool. Join us on June 13th – 14th in Santa Clara, CA to learn about Gradle and the ecosystem tools it supports.   To register, visit