错误:[错误] com.googlecode.flyway.core.api.FlywayException:无法确定类路径位置的URL:db / migration(ClassLoader:ClassRealm [plugin> com.googlecode.flyway:flyway-maven-plugin:2.1。 1,父母:sun.misc.Launcher$AppClassLoader@43be2d65])
我跟着快速启动,所以我还没有做任何复杂的事情。
pom.hml
<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>
我的文件夹结构是规定的PROJECT_ROOT / src / main / resources / db / migration / V1__Base_version.sql:
当我从PROJECT_ROOT执行时,我得到错误:mvn flyway:migrate
不要忘记先调用编译,以确保复制资源。
在我的情况下,我必须明确设置
flyway.locations=classpath:db/migration
在我的application.properties(Spring Boot)中工作。
它必须编译:
mvn compile flyway:migrate
你可以用
<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>
在
<plugin>..</plugin>
然后只需执行mvn编译即可执行迁移任务
从目标目录所在的目录执行mvn命令。