Reputation: 3522
I have a multi-module project as shown below:
Module
|_________sub-module1
| |___pom.xml
|_________sub-module2
| |___pom.xml
|_________sub-module3
| |___pom.xml
|_________sub-module4
| |___pom.xml
|_________pom.xml
I have added some sql scripts for create and drop integration test data in the sub-module2. In the parent pom, I have the below code to setup the database for the integration test.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<configuration>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<url>jdbc:jtds:sqlserver:blah</url>
<settingsKey>sqlsrv-integration-test-creds</settingsKey>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>create-integration-test-data</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<orderFile>ascending</orderFile>
<fileset>
<basedir>${basedir}/src/test/resources</basedir>
<includes>
<include>create-integration-test-data.sql</include>
</includes>
</fileset>
</configuration>
</execution>
<execution>
<id>drop-db-after-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<fileset>
<basedir>${basedir}/src/test/resources</basedir>
<includes>
<include>drop-integration-test-data.sql</include>
</includes>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
Now, when I run mvn clean install
, I am getting error that the file doesn't exist in sub-module1. So I tried adding the scripts to sub-module1. Now, it got executed in sub-module1, but also in sub-module2 and in sub-module3, where it failed since the scripts are not there in sub-module3.
How can I make the scripts get executed only once ?
Upvotes: 1
Views: 304
Reputation: 1111
Answered in comments:
Add the sql-maven-plugin exactly where you need it (sub-module-2) and not in the parent, cause it will be inherited and of course will be executed within every child. – khmarbaise Jul 22 '14 at 9:25
Upvotes: 1