An online markdown blog and knowledge repository.
Set up apt with Heroku cli's latest deb:
# Run this from your terminal.
# The following will add our apt repository and install the CLI:
sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./"
curl -L https://cli-assets.heroku.com/apt/release.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install heroku
Change directory to your project root and commit any final changes.
Pull those changes to "main".
Login to Heroku (website) first, then login to Heroku CLI: heroku login
Update git remotes to include heroku fetch/push urls: git remote add heroku heroku_project_url.git
Push 'main' code to Heroku using git push heroku main
.
Update 'system.properties' to run the app in Heroku by specification in article Specifying a Java version
Specify java runtime version: java.runtime.version=nn
Recommend not specifying java runtime to enable automatic security updates (otherwise dev must do it and re-push).
Devcenter Heroku article Deploying Gradle Apps on Heroku
Heroku supports Java Apps using Gradle that contain the following:
gradle/wrapper/gradle-wrapper.jar
and gradle/wrapper/gradle-wrapper.properties
in git repo and not gitignoredTODO: Take an hour to go through this Gradle tutorial
Create a plain text file at the root of your Spring project named Procfile.
without an extention and paste in the following code:
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/demo-0.0.1-SNAPSHOT.jar
Commit these changes to the deployable branch. In Heroku-cli, launch the webapp with heroku open
Instead of automatic deploys, you can configure Manual Deploy, it is just below Automatic Deploys subsection.
Setting the java compatibility in ...
TODO: Check out section 68.1 Build regarding https behind a proxy.
TODO: This other reference to Force the use of HTTPS
Heroku detects the Java app through presence of a 'pom.xml' file, but this applies to Maven not Gradle.
Heroku uses OpenJDKs Heroku (heroku-18 or heroku-20) or AzulZulu (heroku-22) which are certified Java SE specification compliant.
Postgres DB is automatically provisioned for Java apps that have a dependency on "Postgres JDBC driver" or "pgjdbc-ng driver" in pom.xml
which will auto-populate env variable DATABASE_URL
for you.
stackfellows-wip Heroku Activity
system.properties
file to project root and added java.runtime.version=17
(solves "Invalid source release")gradle build
and used find . -name "*.jar"
to locate jar path (need to fix build cannot find JAR)Procfile
(no period) to project root and added web: java -Dserver.port=$PORT -jar build/libs/app-0.0.1-SNAPSHOT.jar
(as a result of gradle build output step above) (fixes build cannot find JAR error)heroku addons:create heroku-postgresql:hobby-dev
(Fixes failure to connect to datasource error)SERVER_ERROR_WHITELABEL_ENABLED=false
to Vars (fixes Whitelabel error messages)Current Remaining Known Issue: Unable to add to database (Register new user).
It is not clear to me whether/if any/all of these have made a difference:
Once Heroku's postgres addon is included in the App config, the necessary VARs were added automatically by Heroku.
The automatic postgres VARs include the username and password to the postgres installation, and its path!
Spring Docs: System Environment Property Source
Heroku Dev Center: Config Vars
Tom Gregory dot Com: Get Going With Gradle Course (1 hour)
Stack Overflow: Error Connecting to PostgresQL with Spring
Spring dot IO guides: Gradle
Arose 13's Heroku Spring Gradle Example
Heroku Dev Central: Secure Java Web App for Production
Heroku Dev Center: Deploying Spring Boot Apps to Heroku
Heroku Dev Center: Proc File
Heroku Dev Center: Deploying Gradle Apps to Heroku
Heroku Dev Center: Default Web Process Type for Java
heroku pg:psql
Heroku DATABASE_URL: postgres://pqskdaargkkfri:16000d36cf0a21f22155a279dee5bfba4f9fc3004a0678229946d2ce99b195d4@ec2-52-73-184-24.compute-1.amazonaws.com:5432/d2kall4uhuucg2
Note: If only one DB exists then it will be connected by default.
Back to root Readme