Flyway'迁移'ant任务错误:“无法找到sql迁移的路径[...]”

时间:2012-02-13 11:46:23

标签: java ant classpath flyway

我无法使用.sql文件指定目录的正确路径。我尝试将“baseDir”属性设置为不同位置的不同目录(当然是在类路径中)并设置不同的类路径。构建脚本始终包含消息“无法找到sql迁移的路径:[uri to directory with。 sql文件] “。

issue 156看起来不像similar question中那样,因为我删除了SqlMigrationResolver.java中的代码

if (StringUtils.hasText(baseDir) && !new ClassPathResource(baseDir + "/",
    classLoader).exists()) {
  LOG.warn("Unable to find path for sql migrations: " + baseDir);
  return migrations;
}

正如在Comment #9中所说的那样,我仍然抓住了

deployDB:
[flyway:migrate] com.googlecode.flyway.core.exception.FlywayException: Error loading sql migration files
[flyway:migrate] Caused by java.io.FileNotFoundException: class path resource [db/migration/] cannot be resolved to URL because it does not exist

BUILD FAILED
c:\DeployTest\build.xml:208: Flyway Error: com.googlecode.flyway.core.exception.FlywayException: Error loading sql migration files

Flyway落在

resources = new PathMatchingResourcePatternResolver(classLoader)
        .getResources("classpath:" + searchRoot + searchPattern);

它无法执行getResources方法。

它看起来不像bug,看起来我无法使用我的SQL脚本将目录设置为uri =(

请帮我设置这个该死的uri!

我的build.xml:

<target name="init-flyway">
  <taskdef uri="antlib:com.googlecode.flyway.ant"
           resource="com/googlecode/flyway/ant/antlib.xml"
  />
  <property name="flyway.driver" value="${dbDriver}"/>
  <property name="flyway.url" value="${dbUrl}"/>
  <property name="flyway.user" value="${dbScheme}"/>
  <property name="flyway.password" value="${dbPass}"/>
  <property name="flyway.baseDir" value="\db\migration"/>
  <property name="flyway.classpath" value="c:\DeployTest"/>
</target>

<target name="deployDB" depends="init-flyway">
  <flyway:migrate/>
</target>

2 个答案:

答案 0 :(得分:2)

尝试将 flyway.classpath 属性更改为路径

对于您的情况,这意味着更改此内容:

<property name="flyway.classpath" value="c:\DeployTest"/>

到此:

<path id="flyway.classpath">
    <fileset dir="c:\DeployTest"/>
</path>

答案 1 :(得分:2)

而不是:

<path id="flyway.classpath"> 
    <fileset dir="c:\DeployTest"/> 
</path>

使用:

<path id="flyway.classpath">  
      <pathelement location="c:\DeployTest"/>
</path>