My apps on Heroku use a DATABASE_URL. This is simple to parse with Java into a JDBC URL with a user name and password. There's no issue there. However, I have a JOOQ generator and Flyway migrator that have maven plugins and I can't figure out how to get the JDBC URL, User Name, and Password that these plugins require into maven. So currently I do it on app startup which is not ideal. When my app starts I get the DATABASE_URL, parse it, then do the flyway migration and jOOQ code generation. But I would like this to happen during the actual build process, not during application startup.
Basically I need the Heroku Environment variable formatted like (postgres://user:pass@ec2-host:1234/path-to-db) to be accessible in maven as a property like this (jdbc:postgresql://ec2-host:1234?user=user&password=pass).
I think the solution may lie with the maven build helper plugin but I can't get the regex properties specification quite right.
Thanks
There are probably myriad ways to solve this with Maven, but one option is to keep a single properties file in your
/src/main/resources
path, load it using theproperties-maven-plugin
(an example can be seen in the jOOQ-Spring example), and then compose URLs using the individual parts, e.g. jOOQ and Flyway:Heroku:
I have solved this thanks to heroku support. Lukas and Axel you may want to document this for any of your users that are using heroku, want to run your tools in their build (vs code startup), and do not want to hand maintain different environment variables.
We will be using the GMavin Plus Plugin to run some code to parse the DATABASE_URL environment variable into properties prior to running the flyway migration or jOOQ code generation.
First off you need to add Groovy as a dependency:
Then the GMaven plus plugin:
Now you can use ${database.jdbcUrl}, ${database.username}, and ${database.password} in your flyway, jOOQ, or whatever else configurations.