I recently worked on a project where we used Heroku as the deploment engine.
For speed of the project I chose Maven (simply because I know it well and it is VERY good).
Knowing also that Gradle is now becoming the "next build kid" on the block and, for me, recognising that Gradle is easier to configure, I set about the task today of switching the build to Gradle.
This was very simple, and the last "part of the puzzle" after replicating all the functionality was to setup the Heroku parts. By default, we were using the Maven (jetty-runner) boot strapping. Arguably it is easier and lighter to run Jetty Embedded (as per https://github.com/heroku/devcenter-gradle) but I wanted to see what is required to use "jetty-runner"). This was more an excercise in build comparison, that it was "get it onto Heroku".
Heroku will detect a Maven pom.xml, and by default will run
This creates a war. Heroku then runs your app using "whatever" is in the Procfile. The Procfile they suggest looks like this:
The jetty-runner.jar gets in the "target/dependency/" folder due to this Maven Magic.
When Heroku detects a Gradle project, it runs
instead of "gradle package".
So to replicate the same with Gradle I had to write a copy task to get jetty-runner in there, and generate the war and attach that all to a "stage" task.
It is very easy when you look at it, the trick is in the knowing of the API that slows it down. But I resolved it in about 30 minutes.
In short, the changes for Gradle are as follows.
1. Change your Procfile (we will get the jetty-runner.jar in "build/libs") (the war goes there by default)
2. Add a "new" configurations for the depenency of jetty-runner
3. Add a new dependency for Jetty Runner (note I also use newrelic so it goes in there too!)
4. Create a new task which copies the jars from the dependencies "runtimeOnly" We also replicate the Maven method of renaming the jar to have no Version(s).
5. Add a "stage" task, because that is what Heroku will run.
And that is it. When stage is run, it will create a war, and copy jetty-runner.jar into the build/libs folder.
Happy days.