1

我正在尝试让 Gradle liquibaseDiffChangelog 命令与JHipster Sample Gradle App一起使用,但出现以下异常:

liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url ()
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:157)
    at liquibase.integration.commandline.Main.doMigration(Main.java:915)
    at liquibase.integration.commandline.Main.run(Main.java:180)
    at liquibase.integration.commandline.Main.main(Main.java:99)
Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url ()
        at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:247)
        at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
        at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
        ... 3 common frames omitted
Caused by: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url ()
        at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:199)
        ... 5 common frames omitted
:liquibaseDiffChangelog FAILED

我已将 liquibase.gradle 文件修改为以下内容以使用我的本地 MySQL 数据库:

configurations {
  liquibase
}

dependencies {
  liquibase group: 'org.liquibase.ext', name: 'liquibase-hibernate4', version: liquibase_hibernate4_version
}

task liquibaseDiffChangelog(dependsOn: compileJava, type: JavaExec) {
  group = "liquibase"

  classpath sourceSets.main.runtimeClasspath
  classpath configurations.liquibase
  main = "liquibase.integration.commandline.Main"

  args "--changeLogFile=src/main/resources/config/liquibase/changelog/" + buildTimestamp() +"_changelog.xml"
  args "--referenceUrl=hibernate:spring:com.mycompany.myapp.domain?dialect=org.hibernate.dialect.MySQL5Dialect"
  args "--username=root"
  args "--password=password"
  args "--url=jdbc:mysql://localhost:3306/app"
  args "--driver=com.mysql.jdbc.Driver"
  args "diffChangeLog"

}

def buildTimestamp() {
  def date = new Date()
  def formattedDate = date.format('yyyyMMddHHmmss')
  return formattedDate
}

这些参数看起来都是正确的,并且与本指南中描述的使用 Maven 的参数相似。

在这个过程中是否还有其他一些我遗漏的步骤并且我在任何地方都找不到记录?

我需要单独下载 MySQL 连接器并将其放置在某个位置吗?

JHipster Liquibase文档没有提到任何其他步骤。

4

2 回答 2

0

问题是您还需要针对您的 liquibase 配置 url 应该运行差异。您需要编辑的配置文件是应用程序根目录下 gradle 文件夹中的 liquibase.gradle:

args "--changeLogFile=src/main/resources/config/liquibase/changelog/" + buildTimestamp() +"_changelog.xml"
args "--referenceUrl=hibernate:spring:io.github.jhipster.sample.domain?dialect=&hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy"
args "--username=jhipsterGradleSampleApplication"
args "--password="
args "--url=jdbc:mysql://localhost:3306/yourDB"
args "--driver=com.mysql.jdbc.Driver"
args "diffChangeLog"

您需要更改 url、用户名和密码才能使用您的数据库。干杯!

于 2016-09-27T20:04:11.717 回答
0

使用 ?dialect=org.hibernate.dialect.MySQL5InnoDBDialect"

于 2016-12-13T17:50:54.873 回答