I have a spring boot gradle app which I could run successfully on my PC by doing:
heroku local
It can also deploy on heroku successfully wh
According to the documentation:
The Gradle buildpack will automatically detect the use of the Spring Boot and Ratpack web frameworks.
The web
command should be overridden only if needed. If you're using Spring Boot, you shouldn't need to specify a Procfile
at all.
Delete it, and get your app running without further configuration.
You don't need to modify your stage task for that.
In your gradle.build file, make sure to give a name to your built artifact like this.
jar {
baseName = 'app'
version = '0.0.1'
}
With that been done, and the following in Procfile
, it should just run fine.
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/app-0.0.1.jar
I found that if name is not explicitly defined, heroku seems to name the artifact something like build-{buildNumber}.jar
and no wonder it will never find the app.jar
.
Also, if not set already, the build pack needs to be set.
heroku config:set GRADLE_TASK="build"
I eventually found a very helpful thread here: Running Spring app built with gradle on Heroku
Which helped me with my problem - this thread seems to be more detail than Heroku's official guide.
You must add the following code to your build.gradle file:
task stage(type: Copy, dependsOn: [clean, build]) {
from jar.archivePath
into project.rootDir
rename {
'app.jar'
}
}
stage.mustRunAfter(clean)
clean << {
project.file('app.jar').delete()
}
Then, point your Procfile to the app.jar:
web: java $JAVA_OPTS -jar app.jar