I'm starting postgres container with maven docker plugin and then use the DB to generate some artefacts in later steps.
<plugin>
…
<artifactId>docker-maven-plugin</artifactId>
…
<configuration>
<images>
<image>
...
<name>postgres:11</name>
...
</image>
</images>
</configuration>
<executions>
<execution>
<id>start-postgres-container</id>
<phase>generate-sources</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-postgres-container</id>
<phase>process-sources</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
The issue I have is that when there is some error with any operations between start
and stop
above, then maven leaves the running container and consecutive build attempts will fail so one has to put down the leftover container manually first.
Is there a way/plugin in maven to specify some finally
action/phase? So that in case of failure in build scripts one would still be able to release some resources which might've been already reserved?