2014-05-06 49 views
10

我試圖通過maven集成開始使用flyway,但無法使其工作。FlywayException:無法掃描位置中的SQL遷移:classpath:db/migration

我跟着文件似乎很簡單,所以似乎沒有奇怪的事情做。

pom.xml的如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.test</groupId> 
    <artifactId>test</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 


    <build> 
     <plugins> 
      <!-- Flyway plugin configuration --> 
      <plugin> 
       <groupId>org.flywaydb</groupId> 
       <artifactId>flyway-maven-plugin</artifactId> 
       <version>3.0</version> 
       <configuration> 
        <url>jdbc:mysql://localhost:3306/test</url> 
        <user>test_fede</user> 
        <password>test_fede</password> 
       </configuration> 
       <dependencies> 
        <dependency> 
         <groupId>mysql</groupId> 
         <artifactId>mysql-connector-java</artifactId> 
         <version>5.1.21</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>com.google.guava</groupId> 
      <artifactId>guava</artifactId> 
      <version>13.0.1</version> 
     </dependency> 

     <!-- DB dependencies --> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.21</version> 
     </dependency> 

     <!-- Test dependencies --> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.1</version> 
      <scope>compile</scope> 
     </dependency> 
    </dependencies> 
</project> 

我的目錄資源/ DB /遷移/沒有任何遷移呢。

當我發出遷徙路線:在Cygwin上的信息或在cmd我得到了一個遷徙路線錯誤:

$ mvn compile flyway:info 
[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Unnamed - com.test:test:jar:0.0.1-SNAPSHOT 
[INFO] task-segment: [compile, flyway:info] 
[INFO] ------------------------------------------------------------------------ 
[INFO] [resources:resources {execution: default-resources}] 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] [compiler:compile {execution: default-compile}] 
[INFO] Nothing to compile - all classes are up to date 
[INFO] [flyway:info {execution: default-cli}] 
[INFO] Database: jdbc:mysql://localhost:3306/test (MySQL 5.5) 
[INFO] ------------------------------------------------------------------------ 
[ERROR] BUILD ERROR 
[INFO] ------------------------------------------------------------------------ 
[INFO] org.flywaydb.core.api.FlywayException: Unable to scan for SQL migrations in location: classpath:db/migration 

Embedded error: Unable to determine URL for classpath location: db/migration (ClassLoader: [email protected]) 
[INFO] ------------------------------------------------------------------------ 
[INFO] For more information, run Maven with the -e switch 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1 second 
[INFO] Finished at: Tue May 06 11:06:15 CST 2014 
[INFO] Final Memory: 17M/223M 
[INFO] ------------------------------------------------------------------------ 

能給我一隻手在此?

Thans很多。

回答

9

那麼,只是爲了你知道。

我發現了這個問題,當我們在我們的環境中設置flyway時發生了這個問題,但是我們沒有任何要執行的遷移。

它不應該顯示類路徑錯誤,但幸運的是它的工作。

順便說一句,我發現了另一個問題是,執行初始化後,如果我們用信息顯示沒有檢查。如果我們用V1然後信息添加新的遷移不會表現出來,除非我們將其更改爲V1_1

希望能幫到

+0

這可能是由於如果輸入目錄爲空,maven不會創建輸出目錄。 P.S .:你可能不需要初始化。這僅適用於現有的數據庫。對於新的遷移就足夠了。 –

10

這如果編譯目標不是之前執行也發生呼叫飛路:遷移。其實這是包含在快速入門手冊。它說:

mvn compile flyway:migrate

但是如果你錯過了這個細節,並開始只是調用mvn flyway:migrate,SQL文件不會被複制到目標目錄(實際上是目標目錄甚至不存在),你會得到這個神祕的錯誤。

4

我遇到了同樣的問題。就我而言,我在導致問題的錯誤目錄中有我的遷移腳本。我將腳本V1__Create_person_table.sql移動到資源/ db/migration /的正確目錄,並且它工作正常!

0

我面臨同樣的問題。但是當我敏銳地觀察日誌時,我發現flywaydb正在查看腳本的db/migration文件夾,但是我的腳本在db/migrate中。所以,在更正從db/migrate到db/migration的路徑之後,它可以正常工作!!