Export Full Database Example

The following example exports all tables to a dataset file after test phase. See also [_excluding_tables] below for filtering options.

<project>
  [...]
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <groupId>org.dbunit</groupId>
        <artifactId>dbunit-maven-plugin</artifactId>
        <version>1.3.1-SNAPSHOT</version>

        <!--jar file that has the jdbc driver -->
        <dependencies>
          <dependency>
            <groupId>your.vendor.group</groupId>
            <artifactId>your.vendor.artifactId</artifactId>
            <version>x.y</version>
          </dependency>
        </dependencies>

        <!-- common configurations -->
        <configuration>
          <driver>com.vendor.jdbc.Driver</driver>
          <url>jdbc:vendor:mydatabase</url>
          <username>a.username</username>
          <password>a.password</password>
          [....]
        </configuration>

        <executions>
          <execution>
            <phase>test</phase>
            <goals>
              <goal>export</goal>
            </goals>
            <!-- specific configurations -->
            <configuration>
              <format>xml</format>
              <dest>target/dbunit/export.xml</dest>
            </configuration>
          </execution>
          [...]
        </executions>

        [...]
      </plugin>
      [...]
    </plugins>
    [...]
  </build>
  [...]
</project>

Excluding Tables

When no explicit <tables> or <queries> are configured, use <excludes> to filter which tables are included by regex pattern.

Exclude tables by name pattern

Patterns are matched against the table name as returned by JDBC metadata (case is database-specific; use (?i) for case-insensitive matching).

<configuration>
  <format>xml</format>
  <dest>target/dbunit/export.xml</dest>
  <excludes>
    <exclude>(?i)flyway_.*</exclude>
    <exclude>(?i)quartz_.*</exclude>
    <exclude>(?i)batch_.*</exclude>
  </excludes>
</configuration>

Exclude empty tables

<configuration>
  <format>xml</format>
  <dest>target/dbunit/export.xml</dest>
  <excludeEmptyTables>true</excludeEmptyTables>
</configuration>

Combine both filters

<configuration>
  <format>xml</format>
  <dest>target/dbunit/export.xml</dest>
  <excludes>
    <exclude>(?i)flyway_.*</exclude>
  </excludes>
  <excludeEmptyTables>true</excludeEmptyTables>
</configuration>