Liquibase 离线:给定数据库的驱动程序错误 URL

Liquibase Offline : Wrong driver for the given database URL

我正在尝试为 Mysql 数据库生成 SQL 脚本。为此,我使用带有 udateSql 目标的 maven liquibase 插件:

        <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.0.5</version>
            <configuration>
                <propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
            </configuration>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>updateSQL</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这与配置为访问已经 运行 MySql 服务器的 liquibase.properties 文件配合得很好:

#liquibase.properties
driver: com.mysql.cj.jdbc.Driver
classpath: lib/mysql-connector-java-5.0.5-bin.jar
url:jdbc:mysql://localhost:3306/mydb?createDatabaseIfNotExist=true
username: root
password: pass
changeLogFile:changelog-master.xml
logLevel: finest

但是,我只想生成脚本 而没有 运行 数据库。为此,我想使用离线数据库功能。理论上,像这样的 liquibase.properties 就足够了:

#liquibase.properties
url:offline:mysql?catalog=mydb
changeLogFile:changelog-master.xml
logLevel: finest

但是,如果我那样做,它会抱怨没有设置驱动程序。如果我像以前一样添加驱动程序:

#liquibase.properties
driver: com.mysql.cj.jdbc.Driver
classpath: lib/mysql-connector-java-5.0.5-bin.jar
url:offline:mysql?catalog=avisporra
username:null
password:null
changeLogFile:changelog-master.xml
logLevel: finest

我收到下一个错误:

liquibase.exception.DatabaseException: Connection could not be created to offline:mysql?catalog=mydb with driver com.mysql.cj.jdbc.Driver.  Possibly the wrong driver for the given database URL 

关于如何使用离线 URL 我是否遗漏了什么? 感谢您的帮助:)

所以问题出在我使用的插件版本上。我从 liquibase documentation for the Maven plugin 复制了插件配置,不幸的是,它指定了插件的旧版本(版本 3.0.5)。离线 url 已在 3.1 中添加。所以只需将插件版本更改为最新版本(现在是版本 3.6.1 ),离线 url 就可以毫无问题地工作。所以在 pom.xml 中,插件版本应该如下所示:

            <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
            </configuration>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>updateSQL</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

还有 liquibase.properties 这样的:

#liquibase.properties
url:offline:mysql
changeLogFile:changelog-master.xml
logLevel: finest

有了这个,它将在 /target/liquibase 下生成 SQL 脚本,而不需要 运行 MySql 服务器。