I have Flyway set up in my project with the following directory layout (excluding irrelevant directories):
$ tree database
database
├── lib
│ ├── flyway-ant-2.0.1.jar
│ ├── flyway-core-2.0.1.jar
│ ├── migrate.jar
│ ├── spring-beans-3.1.2.RELEASE.jar
│ ├── spring-core-3.1.2.RELEASE.jar
│ ├── spring-dao-2.0.8.jar
│ └── spring-jdbc-3.1.2.RELEASE.jar
└── updates
├── java
│ └── database
│ └── migrate
│ └── V1_0__create_posts.java
└── sql
└── V1_1__create_users.sql
And the relevant part of build.xml (flyway.url and flyway.driver are set in a properties file not included here—Flyway has no problem talking to the database):
<target name="path">
<path id="migrate.build.path">
<fileset dir="database/lib">
<include name="flyway-*.jar"/>
</fileset>
<fileset dir="database/lib">
<include name="spring-*.jar"/>
</fileset>
</path>
<path id="flyway.lib.path">
<fileset dir="database/lib">
<include name="flyway-*.jar"/>
</fileset>
</path>
<path id="flyway.classpath">
<fileset dir="lib" includes="h2-*.jar"/>
<fileset dir="database/lib" includes="migrate.jar"/>
</path>
</target>
<target name="compile" depends="path">
<mkdir dir="build"/>
<javac srcdir="database/updates/java" destdir="build" includeantruntime="false" classpathref="migrate.build.path"/>
<copy todir="build">
<fileset dir="database/updates" excludes="**/*.java"/>
</copy>
<jar destfile="database/lib/migrate.jar" basedir="build" includes="sql/**,database/migrate/**"/>
</target>
<target name="init" depends="compile,path">
<!-- imported tasks -->
<taskdef uri="antlib:com.googlecode.flyway.ant" resource="com/googlecode/flyway/ant/antlib.xml" classpathref="flyway.lib.path"/>
<property name="flyway.locations" value="sql,database.migrate"/>
</target>
<!-- flyway tasks -->
<target name="db:clean" depends="init">
<flyway:clean/>
</target>
<target name="db:init" depends="init">
<flyway:init/>
</target>
<target name="db:migrate" depends="init">
<flyway:migrate/>
</target>
<target name="db:validate" depends="init">
<flyway:validate/>
</target>
<target name="db:info" depends="init">
<flyway:info/>
</target>
<target name="db:status" depends="init,db:info"/>
<target name="db:repair" depends="init">
<flyway:repair/>
</target>
Here is the layout of the migrations JAR created in the compile target:
$ unzip -l database/lib/migrate.jar
Archive: database/lib/migrate.jar
Length Date Time Name
-------- ---- ---- ----
0 01-14-13 16:27 META-INF/
103 01-14-13 16:27 META-INF/MANIFEST.MF
0 01-14-13 16:21 database/
0 01-14-13 16:27 database/migrate/
0 01-14-13 16:27 sql/
538 01-14-13 16:27 database/migrate/V1_0__create_posts.class
0 01-14-13 16:27 sql/V1_1__create_users.sql
-------- -------
641 7 files
And here is the output from flyway:info:
[flyway:info] +-------------+------------------------+---------------------+---------+
[flyway:info] | Version | Description | Installed on | State |
[flyway:info] +-------------+------------------------+---------------------+---------+
[flyway:info] | 0 | << Flyway Init >> | 2013-01-14 14:14:09 | Missing |
[flyway:info] | 1.1 | create users | | Pending |
[flyway:info] +-------------+------------------------+---------------------+---------+
Flyway is not discovering the .class files. What am I doing wrong here?
Edit: If anyone knows of a working example of Flyway set up with Ant (no Maven, no Ivy), it would be much appreciated.
Update
It turns out Flyway will find JdbcMigration classes, but not SpringJdbcMigration.
This migration is successfully loaded:
/* database/updates/java/database/migrate/V1_0__create_posts.java */
import com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration;
import java.sql.Connection;
public class V1_0__create_posts implements JdbcMigration {
public void migrate(Connection conn) throws Exception {
conn.createStatement().execute(
"create table posts (id integer primary key, title varchar(255), body text)"
);
}
}
But this one is skipped:
/* database/updates/java/database/migrate/V1_0__create_posts.java */
import org.springframework.jdbc.core.JdbcTemplate;
import com.googlecode.flyway.core.api.migration.spring.SpringJdbcMigration;
public class V1_0__create_posts implements SpringJdbcMigration {
public void migrate(JdbcTemplate template) throws Exception {
template.execute(
"create table posts (id integer primary key, title varchar(255), body text)"
);
}
}
Here is the Ant debug output when using a SpringJdbcMigration:
[antlib:com.googlecode.flyway.ant] Could not load definitions from resource com/googlecode/flyway/ant/antlib.xml. It could not be found. [4/873]
[flyway:info] Database: H2 1.2
[flyway:info] DDL Transactions Supported: false
[flyway:info] Schema: PUBLIC
[flyway:info] No metadata table upgrade necessary
[flyway:info] Spring Jdbc available: false
[flyway:info] Scanning for resources at 'database/migrate' (Prefix: 'V', Suffix: '.sql')
[flyway:info] Scanning URL: jar:file:.../flyway-sample/database/lib/migrate.jar!/database/migrate
[flyway:info] JBoss VFS v2 available: false
[flyway:info] Filtering out resource: database/migrate/ (filename: )
[flyway:info] Filtering out resource: database/migrate/V1_0__create_posts.class (filename: V1_0__create_posts.class)
[flyway:info] Scanning for classes at 'database/migrate' (Implementing: 'com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration')
[flyway:info] Scanning URL: jar:file:.../flyway-sample/database/lib/migrate.jar!/database/migrate
[flyway:info] Filtering out resource: database/migrate/ (filename: )
[flyway:info] Scanning for resources at 'db/migration' (Prefix: 'V', Suffix: '.sql')
[flyway:info] Unable to determine URL for classpath location: db/migration (ClassLoader: AntClassLoader[.../flyway-sample/lib/h2-1.2.135.jar:.../flyway-sample/database/lib/migrate.jar])
[flyway:info] Scanning for classes at 'db/migration' (Implementing: 'com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration')
[flyway:info] Unable to determine URL for classpath location: db/migration (ClassLoader: AntClassLoader[.../flyway-sample/lib/h2-1.2.135.jar:.../flyway-sample/database/lib/migrate.jar])
[flyway:info] Scanning for resources at 'sql' (Prefix: 'V', Suffix: '.sql')
[flyway:info] Scanning URL: jar:file:.../flyway-sample/database/lib/migrate.jar!/sql
[flyway:info] Filtering out resource: sql/ (filename: )
[flyway:info] Found resource: sql/V1_1__create_users.sql
[flyway:info] Scanning for classes at 'sql' (Implementing: 'com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration')
[flyway:info] Scanning URL: jar:file:.../flyway-sample/database/lib/migrate.jar!/sql
[flyway:info] Filtering out resource: sql/ (filename: )
[flyway:info] Filtering out resource: sql/V1_1__create_users.sql (filename: V1_1__create_users.sql)
[flyway:info] +-------------+------------------------+---------------------+---------+
[flyway:info] | Version | Description | Installed on | State |
[flyway:info] +-------------+------------------------+---------------------+---------+
[flyway:info] | 0 | << Flyway Init >> | 2013-01-14 14:14:09 | Missing |
[flyway:info] | 1.1 | create users | | Pending |
[flyway:info] +-------------+------------------------+---------------------+---------+
Turns out I didn’t have all the Spring JDBC migration dependencies.
I downloaded the latest Flyway (2.0.3) with Ant & Spring dependencies, added the new JARs to the classpath, and the Spring JDBC migrations are now found by Flyway.