2. migrate from maven to gradle (heroku only)
install heroku cli, register (if has no account) and login
brew install heroku
heroku login
clone my heroku maven (java buildpack) example project which has already ptrepared gradle stuff
git clone https://github.com/daggerok/heroku-java-buildpack-example.git
rm -rf .git .mvn mvnw* pom.xml heroku.yml
add requred heroku-gradle setup
echo "task stage(dependsOn: 'build')" >> build.gradle
create heroku app and deploy to it with development profile
git init .
heroku create daggerok-gradle-buildpack
echo "web: SPRING_PROFILES_ACTIVE=dev ./build/libs/*.jar" > Procfile
git add .
git commit -am "First blood!"
git push heroku master
heroku logs -t
# find output: The following profiles are active: dev,spring-boot,data-jpa
key points here (if you just create app from scratch):
-
you need prepare gradle
stage
task for buildecho "task stage(dependsOn: 'build')" >> build.gradle
-
you need prepare Procfile with bash application startup command (in out case it’s:
./build/libs/*.jar
)echo "web: SPRING_PROFILES_ACTIVE=dev ./build/libs/*.jar" > Procfile
-
you need install gradle wrapper in your project
gradle wrapper git add -f gradle* git commit -am "Add gradle wrapper"
3. going production
for production (heroku) version add postgres database
heroku addons:create heroku-postgresql:hobby-dev
now let’s configure correct heroku URL and switch spring-boot app to production prpofile which is using postgres database:
echo "web: SPRING_PROFILES_ACTIVE=prod APP_BASE_URL=https://daggerok-gradle-buildpack.herokuapp.com ./build/libs/*.jar" > Procfile
git add .
git commit -am "Setup right heroku application environment variables"
git push heroku master
just FYI
git remote -v
heroku https://git.heroku.com/daggerok-gradle-buildpack.git (fetch)
heroku https://git.heroku.com/daggerok-gradle-buildpack.git (push)
link:
generated by generator-jvm yeoman generator (java-spring-boot)