1

我正在尝试在具有多个数据库的复杂 ERP 上使用 flyway,但我没有找到任何让它运行的提示。我正在与 Hudson 一起使用 ant 脚本来构建整个系统。因此,我创建了一个包含以下内容的 migrate.xml 文件,并在下面的任务中多次调用该脚本。但是,该任务只运行一次并出现任何错误。如果我两次调用该任务,则会引发异常。有什么想法可以解决这个问题吗?

提前致谢。

--exception
BUILD FAILED
/home/raphael/Development/ufpb/sig/sig-migration-fly-way/build.xml:6: The following error occurred while executing this line:
/home/raphael/Development/ufpb/sig/sig-migration-fly-way/migrate.xml:27: Flyway Error: java.lang.IllegalArgumentException: null source
    at java.util.EventObject.<init>(EventObject.java:38)
    at org.apache.tools.ant.BuildEvent.<init>(BuildEvent.java:93)
    at org.apache.tools.ant.Project.fireMessageLogged(Project.java:2351)
    at org.apache.tools.ant.Project.log(Project.java:492)
    at com.googlecode.flyway.ant.AntLog.debug(AntLog.java:42)
    at com.googlecode.flyway.core.dbsupport.DbSupportFactory.createDbSupport(DbSupportFactory.java:59)
    at com.googlecode.flyway.core.Flyway.execute(Flyway.java:1159)
    at com.googlecode.flyway.core.Flyway.info(Flyway.java:967)
    at com.googlecode.flyway.ant.MigrateTask.doExecuteWithMigrationConfig(MigrateTask.java:157)
    at com.googlecode.flyway.ant.AbstractMigrationLoadingTask.doExecute(AbstractMigrationLoadingTask.java:271)
    at com.googlecode.flyway.ant.AbstractFlywayTask.execute(AbstractFlywayTask.java:329)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)

--task
  <target name="test">
     <ant antfile="migrate.xml">
      <property name="dir" value="sigaa"/>
      <property name="database" value="demo_development"/>
     </ant>
  </target>   

---migrate.xml
<?xml version="1.0"?>

<project name="migrations" default="deploy" basedir="." xmlns:flyway="antlib:com.googlecode.flyway.ant">

   <path id="flyway.classpath">
       <!-- include all jars containing jdbc drivers -->
       <!-- include all jars and directories containing sql migrations -->
       <!-- include all jars and directories containing compiled java migrations -->
        <fileset dir="lib">
            <include name="*.jar" />
    </fileset>       
   </path>

   <taskdef uri="antlib:com.googlecode.flyway.ant"
            resource="com/googlecode/flyway/ant/antlib.xml" />

    <property name="flyway.driver" value="org.postgresql.Driver"/>
    <property name="flyway.initOnMigrate" value="true"/>
    <property name="flyway.validateOnMigrate" value="true"/>
    <property name="flyway.url" value="jdbc:postgresql://localhost:5432/${database}"/>
    <property name="flyway.user" value="***"/>
    <property name="flyway.password" value="****"/> 
    <property name="flyway.table" value="schema_version_${dir}"/>               
    <property name="flyway.locations" value="filesystem:db/migrations/${dir}"/>

    <target name="migrate">
        <flyway:migrate />
    </target>

    <target name="deploy" depends="migrate">
        <flyway:info />
    </target>                       
</project>
4

1 回答 1

1

由于 org.apache.tools.ant.Project 类的 log 方法,问题出在 flyway-ant 项目的 com.googlecode.flyway.ant.AntLog 类中。第二次执行,代码antProject.getThreadTask(Thread.currentThread())返回null,出现错误。我放了一个 if 语句来解决问题,如下面的代码

if (task != null)
    antProject.log(task, message, null, Project.MSG_VERBOSE);
else
    antProject.log(message, null, Project.MSG_VERBOSE);
于 2013-04-29T00:09:20.697 回答