Skip to main content

Announcing the new Maven Schemaspy Plugin

Posted by johnsmart on August 13, 2008 at 4:29 PM PDT

Schemaspy is a little known but very useful database analysis tool that generates an interactive graphical representation of your database structure, in terms of tables and relationships. This is a very cool tool that works wonders when you need to understand a new database structure. Indeed Schemaspy gets a chapter in the Java Power Tools book. A sample Schemaspy report can be found here.

If you have a Maven project, this is a great thing to have in your Maven reports. Unfortunately, there is no official Maven plugin for Schemaspy (at least, not for Maven 2). So, to get around this, I wrote my own. This plugin lets you generate SchemaSpy reports from within your pom.xml file - they appear in the Maven reports just like ordinary Javadoc documentation.

For the moment, this plugin is deployed in the Wakaleo Maven repository, so you need to add a reference to this repository in your POM file or your settings.xml file, as shown here:


    <pluginRepositories>
        ...
        <pluginRepository>
            <id>Wakaleo Repository</id>
            <url>http://maven.wakaleo.com/repos/</url>
        </pluginRepository>
        ...             
    </pluginRepositories>

The plugin is pretty easy to use: you just provide the details you would expect to access your database (JDBC URL, username, password,...). The full JDBC URL works fine. Or you can just provide the database name, type, and host address, which makes the configuration a bit lighter. The following listing illustrates how to use the plugin:


<project>
  ...
  <reporting>
    <plugins>
        <plugin>
            <groupId>com.wakaleo.schemaspy</groupId>
            <artifactId>maven-schemaspy-plugin</artifactId>
            <version>1.0</version>
            <configuration>
                <databaseType>mysql</databaseType>
                <database>testdb</database>
                <host>localhost</host>
                <user>scott</user>
                <password>tiger</password>
            </configuration>
        </plugin> 
    </plugins>
  </reporting>
</project>

The plugin documentation can be found here. In particular, look at the usage page for more details on how to use the plugin.

Comments

I couldn't figure out how to run it as "mvn schemaspy:schemaspy". I get, "The plugin 'org.apache.maven.plugins:maven-schemaspy-plugin' does not exist". Running "mvn com.wakaleo.schemaspy:maven-schemaspy-plugin:1.0:schemaspy" does appear to work, though it sure is ugly. Is there a better way of doing this?