0

I would like to clean and fill two different databases for integration testing with a Maven project. I use the sql-maven-plugin, but I wasn't able to make it handle different databases (I can have only one plugin declaration for the sql-maven-plugin, and the configuration is shared between its executions).

How do you guys solve that? Is there any workaround to solve this issue?

Thanks in advance!

Tunaki
  • 132,869
  • 46
  • 340
  • 423
rlegendi
  • 10,466
  • 3
  • 38
  • 50

1 Answers1

3

You can simply define all of the configuration within each individual execution section and configure as required. Instead of having a shared configuration.

So here is an example to connect to two different HSQLDB databases:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sql-maven-plugin</artifactId>
    <version>1.5</version>

    <dependencies>
      <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.2.9</version>
      </dependency>
      <!-- you could add dependencies to other database drivers here -->
    </dependencies>

    <executions>
      <!-- execution against database 1 -->
      <execution>
        <id>database1</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <!-- specific configuration for execution against database1 -->
        <configuration>
          <driver>org.hsqldb.jdbcDriver</driver>
          <url>jdbc:hsqldb:hsql://localhost:9999/database1</url>
          <username>sa</username>
          <password></password>
          <sqlCommand>select count(TYPE_NAME) from INFORMATION_SCHEMA.SYSTEM_TABLES</sqlCommand>
        </configuration>
      </execution>
      <!-- execution against database 2 -->
      <execution>
        <id>database2</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <!-- specific configuration for execution against database2 -->
        <configuration>
          <driver>org.hsqldb.jdbcDriver</driver>
          <url>jdbc:hsqldb:hsql://localhost:8888/database2</url>
          <username>sa</username>
          <password></password>
          <sqlCommand>select count(TYPE_NAME) from INFORMATION_SCHEMA.SYSTEM_TABLES</sqlCommand>
        </configuration>
      </execution>
    </executions>
  </plugin>
DB5
  • 13,553
  • 7
  • 66
  • 71
  • I was experimenting something like this, but it caused me that I do not see any of the sql-maven-plugin executions, strange. Probably I've made some errors (although I had an outer-level configuration too). Gonna check it, thanks! – rlegendi May 03 '13 at 11:31
  • You need to make sure you give each execution section a unique `id` tag otherwise I think they might overwrite each other. I used the example given locally and it worked without any problems. – DB5 May 03 '13 at 11:33
  • Yeah, their ID is different, let me check if I can apply this solution. – rlegendi May 03 '13 at 11:36
  • Ahh, it was a silly misconfiguration, I was modifying a Linux profile on a Windows dev environemnt :-))) Thx DB5, your solution is perfect. – rlegendi May 03 '13 at 12:06