I have a bunch of SQL commands bound to the pre-integration-test
phase whose job is to create a "test" database and point the application to it.
Sometimes, I want to just "rebuild" my test database without all the other stuff in the lifecycle. For example, if my test is catastrophically failing and screwing up the test database, I may have to rebuild it several times until I figure out what the problem is.
Here's what my POM looks like:
<profile>
<id>test-setup-teardown</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.3</version>
<dependencies>
<dependency>
<groupId>${database-dependency-groupId}</groupId>
<artifactId>${database-dependency-artifactId}</artifactId>
<version>${database-dependency-version}</version>
</dependency>
</dependencies>
<configuration>
<url>${test-database-admin-url}</url>
<username>${test-database-admin-username}</username>
<password>${test-database-admin-password}</password>
<driver>${database-driver}</driver>
<autocommit>true</autocommit>
</configuration>
<executions>
<execution>
<id>test-database-pre-setup</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<sqlCommand>${test-database-teardown}</sqlCommand>
<onError>continue</onError>
</configuration>
</execution>
<execution>
<id>test-database-setup</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<sqlCommand>${test-database-setup}</sqlCommand>
</configuration>
</execution>
<execution>
<id>test-database-schema</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>${test-database-url}</url>
<username>${database-user}</username>
<password>${database-password}</password>
<srcFiles>
<srcFile>${basedir}/metadata/build/database/${database-engine}/appx.sql</srcFile>
</srcFiles>
</configuration>
</execution>
<execution>
<id>test-database-teardown</id>
<phase>post-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<sqlCommand>${test-database-teardown}</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
How can I run all the executions of this profile? Something like mvn sql:execute
only runs one of the executions (the last, I think).
I've tried making the bound phase be a property, and then allow the user to specify another profile which changes the default from pre-integration-test
to validate
, but explaining to someone why rebuilds are executed thusly:
mvn validate -Pforce-rebuild,test-setup-teardown
simply enforces the fact that non-toy projects have a lot of magic in the POM. Please, show me the way!
<ed>Maybe a good solution would be a way to run executions by id from the command line?</ed>