I didn't figure it out with Maven, since I switched to using the API version with Spring (which seems to be better in all respects).
Initially it had the same problem - the bean's init-method="migrate"
would fail on non-empty schemas, requiring init
be called first. However by looking at the source of the Flyway bean, I noticed I could just set initOnMigrate
to true, and it would do it for me. I'm not sure why this isn't in the documentation; it's not trivially obvious to someone who doesn't play around with beans very much.
Anyway, if you also have a non-empty schema about which Flyway is complaining, the bean in applicationContext.xml
should look like this:
<bean id="flyway" class="com.googlecode.flyway.core.Flyway" init-method="migrate">
<property name="dataSource" ref="dataSource" />
<property name="initOnMigrate" value="true" />
</bean>