我正在使用 maven docker 插件启动 postgres 容器,然后在后面的步骤中使用数据库生成一些人工制品。
<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>
我遇到的问题是,当两者之间的任何操作出现错误时start
,stop
maven 会离开正在运行的容器,并且连续的构建尝试将失败,因此必须先手动放下剩余的容器。
maven 中有没有办法/插件来指定一些finally
动作/阶段?这样在构建脚本失败的情况下,仍然能够释放一些可能已经被保留的资源?