Integrate ant with dbdeploy not in the classpath
The need for a schema versioning system at LocaModa finally became a priority this sprint so I’ve spent the past few days researching and diving into implementation. After comparing LiquiBase, dbdeploy, MIGRATEdb, and dbmigrate I settled on the simple SQL driven solution that dbdeploy provides and started integrating it with our Ant build. Pramod Sadalage over at Agile DBA put up a nice post on the basics but I quickly hit a wall, the MySQL driver was not in my classpath.
As I mentioned earlier we are using Ivy for our dependancy management which makes it difficult to throw jars into the Ant classpath since they are automatically downloaded at build time. So far this hasn’t been an issue since most Ant tasks allow you to specify the classpath as a parameter within the task. Dbdeploy does not. Goggling around I quickly found a posting that suggested patching the dbdeploy ant task as the only way to go, so off I went. However, a few hours later, after wandering through the Java classloader abyss I was stymied.
I backed out of the changes and decided a different tactic was needed; back to Goggle I went. This time I came across a post which suggested all I needed was to add the jar to the taskdef classpath Could it really be that easy? Switching back to my build.xml I doctored up the dbdeploy taskdef, kicked off a build and sure enough the damn thing worked.
So, if you want to centrally manage your ant dependencies, just remember to add the necessary classpath references to your taskdefs, like so:
<taskdef name="dbdeploy"
classname="net.sf.dbdeploy.AntTarget"
classpath="${dbdeploy.jar}:${mysql-connector.jar}"/>
Tags: ant, classpath, dbdeploy, ivy, taskdef
You can comment below, or link to this permanent URL from your own site.
January 27, 2009 at 3:23 pm
You might also try the classpathref attribute for taskdef so that you can define you classpath in a “path” element and use the same classpath path element for other things. This way you can add stuff to the single path element and all of the other things that use that for the classpath get updated.
Nice post.
January 27, 2009 at 3:52 pm
I actually do. The real code is:
<taskdef name=”dbdeploy”
classpathref=”dbdeploy.path”
classname=”net.sf.dbdeploy.AntTarget”/>
Where dbdeploy.path is set by:
<ivy:cachepath pathid=”dbdeploy.path”
conf=”dbdeploy” />
Which in turn comes from the dbdeploy conf in ivy.xml config. But I didn’t want to dive into that in the post.