In my maven project, I have multiple maven profiles. In each profile, I have docker-maven-plugin
and maven-failsafe-plugin
. This is how I have bound goals and phases.
docker-maven-plugin
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>remove</goal>
</goals>
maven-failsafe-plugin
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
I have profiles for each database type (i.e. MySQL, Postgres etc.). What I'm trying to do is that run my integration tests on docker with each database type.
My question is that, can I run mvn with multiple profiles (i.e. mvn clean install -P local-postgres,local-mysql
), so that each profile is executed one after the other? My requirement is not to have 2 docker containers up at once.
What I observed is that pre-integration-test
phases of all profiles run first, and fails with The name "/apim-postgres" is already in use by container xxxxx
. Is that how maven phases are supposed to work when multiple profiles are given?
Is there a way I can get my requirement fulfilled?
I'm not sure if this will work, but if you define each profile independently it should work. You define each plugin twice, one for each profile. The order of execution depends on various factors. I don't know where you have defined the profiles, but if they are defined in the same pom then the order should be the one defined in that pom. See https://www.waltercedric.com/index.php?option=com_content&view=article&id=1795&catid=129&Itemid=332 for more help.