We generate documentation from our tests with Spring REST Docs. When deploying the application to Heroku, by default tests are skipped, as I can see clearly in the logs:
-----> Java app detected
-----> Installing JDK 1.8... done
-----> Installing Maven 3.3.9... done
-----> Executing: mvn -DskipTests clean dependency:list install
[INFO] Scanning for projects...
[INFO]
How can I customize the Maven command that is executed by Heroku?
After a day of searching, I found two possible ways to enable tests for the Heroku build:
pom.xml
Configuration in your pom.xml
overrides command-line arguments when your Maven process is started.
You can undo -DskipTests
by disabling skipTests
in the Maven Surefire Plugin configuration as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
Please note that Heroku adds environment variables when running Maven. Make sure you use an in-memory database when running in the Spring
test
profile, otherwise the build will fail.In my case, I use Flyway for database migrations. For some weird reason, regardless the
spring.datasource.url
in myapplication-test.yml
, Flyway used the environment variable value. If you have the same issue, please note that you can override them too with theargLine
configuration property of the Maven Surefire Plugin.
<argLine>-DDATABASE_URL=jdbc:h2:mem:questflair -DJDBC_DATABASE_URL=jdbc:h2:mem:questflair -DSPRING_DATASOURCE_URL=jdbc:h2:mem:questflair</argLine>
According to the Heroku Java Buildpack documentation, you can customize Maven options and goals.
I didn't try this solution, see Customize Maven for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With