title: Is there a way to specify some kind finally action (build-cleanup phase) in Maven?
body: <p>I'm starting postgres container with maven docker plugin and then use the DB to generate some artefacts in later steps.</p>
  <pre><code>&lt;plugin&gt;
     …
      &lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
      …
      &lt;configuration&gt;
          &lt;images&gt;
              &lt;image&gt;
                  ...
                  &lt;name&gt;postgres:11&lt;/name&gt;
                  ...
              &lt;/image&gt;
          &lt;/images&gt;
      &lt;/configuration&gt;
  
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;start-postgres-container&lt;/id&gt;
              &lt;phase&gt;generate-sources&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;start&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
          &lt;execution&gt;
              &lt;id&gt;stop-postgres-container&lt;/id&gt;
              &lt;phase&gt;process-sources&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;stop&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  
   &lt;/plugin&gt;
  </code></pre>
  <p>The issue I have is that when there is some error with any operations between <code>start</code> and <code>stop</code> above, then maven leaves the running container and consecutive build attempts will fail so one has to put down the leftover container manually first.</p>
  <p>Is there a way/plugin in maven to specify some <code>finally</code> 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?</p>