即使我有 liquibase.properties 文件,也未指定数据库 URL

问题描述

我正在尝试使用 liquibase 运行我的迁移,但由于某些原因,我的 pom 文件找不到我的属性文件。当我运行更新命令时,出现以下错误

The database URL has not been specified either as a parameter or in a properties file.

我使用 exections 标记是因为我希望有多个数据库连接到我的应用程序。 在我添加标签之前,一切正常

pom 文件

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.petapilot</groupId>
    <artifactId>migrations</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Migrations</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>15</java.version>
        <start-class>com.petapilot.migrations.MigrationsApplication</start-class>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>4.3.1</version>
        </dependency>

        <dependency>
            <groupId>MysqL</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <mainClass>${start-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>4.3.1</version>
                <executions>
                    <execution>
                        <id>postgre-update</id>
                        <phase>process-resources</phase>
                        <configuration>
                            <propertyFile>src/main/resources/liquibase_postgre.properties</propertyFile>
                        </configuration>
                        <goals>
                            <goal>update</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>MysqL-update</id>
                        <phase>process-resources</phase>
                        <configuration>
                            <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                        </configuration>
                        <goals>
                            <goal>update</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

解决方法

使用执行时,您必须告诉 Maven 运行哪个目标,以及哪个阶段负责运行目标,如 general plugin config docs 中所述。

当您在顶级 <configuration> 块中指定属性文件时,它适用于所有插件执行。

<executions>
  <execution>
    <configuration>
      <phase>[Maven phase]</phase>
      <goals>
          <goal>[plugin goal to run]</goal>
      </goals>
      <propertyFile>src/main/resources/liquibase.properties</propertyFile>
    </configuration>
  </execution>
</executions>
,

您可能想看看我在 this post 上的回答。这篇文章正在解决类似的问题,答案可能会对您有所帮助。

干杯!!