Flyway not finding my sql migrations in db/migrati

2020-08-21 06:22发布

The error: [ERROR] com.googlecode.flyway.core.api.FlywayException: Unable to determine URL for classpath location: db/migration (ClassLoader: ClassRealm[plugin>com.googlecode.flyway:flyway-maven-plugin:2.1.1, parent: sun.misc.Launcher$AppClassLoader@43be2d65])

I followed the quickstart, so I'm not really doing anything complex yet.

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.cpt.migrations</groupId>
  <artifactId>cpt_migrations</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>cpt_migrations</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.24</version>
    </dependency>
  </dependencies>
  <build>
      <plugins>
          <plugin>
              <groupId>com.googlecode.flyway</groupId>
              <artifactId>flyway-maven-plugin</artifactId>
              <version>2.1.1</version>
              <configuration>
                  <user>root</user>
                  <password></password>
                  <driver>com.mysql.jdbc.Driver</driver>
                  <url>jdbc:mysql://localhost:3306/cpt</url>
              </configuration>
          </plugin>
      </plugins>
  </build>
</project>

And my folder structure is the prescribed PROJECT_ROOT/src/main/resources/db/migration/V1__Base_version.sql:

I get the error when, from the PROJECT_ROOT, I execute: mvn flyway:migrate

标签: flyway
5条回答
【Aperson】
2楼-- · 2020-08-21 06:53

In my case I had to explicitely set

flyway.locations=classpath:db/migration

in my application.properties (Spring Boot) for it to work.

查看更多
The star\"
3楼-- · 2020-08-21 06:56

in my case this error was caused as package with name db.migration was created instead of db -> migration

查看更多
Bombasti
4楼-- · 2020-08-21 06:59

Don't forget to call compile first, to make sure the resources are copied over.

查看更多
爷、活的狠高调
5楼-- · 2020-08-21 07:02

Execute mvn command from directory where target dir is located.

查看更多
贪生不怕死
6楼-- · 2020-08-21 07:06

It has to be compiled:

mvn compile flyway:migrate

You may use

<executions>
          <execution>
            <id>compile</id>
            <phase>compile</phase>
            <goals>
              <goal>migrate</goal>
            </goals>
          </execution>
          <execution>
            <id>clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>

in

<plugin>..</plugin> 

and then just mvn compile is needed for execution of migrate task

查看更多
登录 后发表回答