Grails 3 database-migration-plugin初始化错误

时间:2016-02-01 14:07:39

标签: grails liquibase grails-3.0

我最近在我的grails 3.0.11应用程序中添加了database-migration-plugin。问题是当我尝试运行app时出现以下错误:

ERROR grails.boot.GrailsApp - Application startup failed
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'springLiquibase_dataSource': 
Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: 
java.lang.IllegalArgumentException: Script text to compile cannot be null!

看起来它无法在我的grails-app / migrations文件夹中找到changelog.xml。我的build.gradle文件包含:

buildscript {
    dependencies {
        classpath "org.grails.plugins:database-migration:2.0.0.RC1"
    }
}

sourceSets {
    main {
        resources {
            srcDir 'grails-app/migrations'
        }
    }
}

我还在application.groovy文件中添加了以下行:

grails.plugin.databasemigration.updateOnStart = true
grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.xml']

我非常感谢任何有关如何使数据库迁移插件正常工作的建议。

编辑:

我使用$grails dbm-create-changelog命令

创建了changelog.xml文件

我还添加到build.gradle(由$grails plugin-info database-migration命令建议):

dependencies {
    compile "org.grails.plugins:database-migration:2.0.0.RC1"
}

然后我将其更改为(以下官方文档):

dependencies {
    runtime "org.grails.plugins:database-migration:2.0.0.RC1"
}

然后(如手册中的启动错误所示)我强制liquibase:

dependencies {
    compile 'org.liquibase:liquibase-core:3.3.2'
    runtime 'org.grails.plugins:database-migration:2.0.0.RC1'
}

dependencies {
    compile 'org.liquibase:liquibase-core:3.3.2'
    compile 'org.grails.plugins:database-migration:2.0.0.RC1'
}

问题仍然存在:java.lang.IllegalArgumentException: Script text to compile cannot be null!

6 个答案:

答案 0 :(得分:7)

升级到Grails 3时遇到了同样的问题。

查看grails-database-migration插件的代码,明确配置参数已从列表updateOnStartFileNames更改为单个值updateOnStartFileName

所以当您从

更改配置时
grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.xml']

grails.plugin.databasemigration.updateOnStartFileName = 'changelog.xml'

它应该再次起作用。

答案 1 :(得分:2)

我遇到了类似的错误。在我的情况下,我们有一些查找表,我们使用手工制作的脚本进行填充,该脚本包含在主要的changelog.groovy中,如:

include file: 'data/001-tablex-data.groovy'

除了文件名不正确 - 它应该是002 -...而不是。错误基本相同,但没有报告指示哪个包含的文件未被发现/解析,这是一个痛苦。因此,如果您手动包含文件,那么除了检查顶级changelog.groovy或changelog.xml之外,还要查找错误命名的文件

答案 2 :(得分:1)

好的,我终于找到了解决方案。也许有一天它会帮助某人。所以我所做的只是删除changelog.groovy(我从XML切换到Groovy)文件。然后我用$grails dbm-create-changelog changelog.groovy命令生成了一个新的。作为最后一步,我运行$grails dbm-changelog-sync,一切都开始正常工作。

答案 3 :(得分:0)

确保:

  1. 您已设置更改日志,即文件grails-app/migrations/changelog.xml存在且有效。
  2. 你如何做到这一点取决于你的情况。该插件的文档有一节介绍如何最初创建文件。

    1. 您的数据源已设置为使用changelog.xml适用的数据库。

答案 4 :(得分:0)

我们遇到此问题的另一个潜在原因是大小写不正确。如果changelog.groovy引用了path/someFile.groovy,但实际名称是path/somefile.groovy,则将出现此错误。确保路径名大小写匹配。

答案 5 :(得分:0)

我也遇到了这个问题,就我而言,问题在于build.gradoe中该块的顺序

sourceSets {
    main {
        resources {
            srcDir 'grails-app/migrations'
        }
    }
}

必须bootRun之前,如以下代码所示。

sourceSets {
    main {
        resources {
            srcDir 'grails-app/migrations'
        }
    }
}

bootRun {
    jvmArgs(
            '-Dspring.output.ansi.enabled=always',
            '-noverify',
            '-XX:TieredStopAtLevel=1',
            '-Xmx1024m')
    sourceResources sourceSets.main
    String springProfilesActive = 'spring.profiles.active'
    systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}

如果将sourceSets放在bootRun之后,您的应用程序将找不到迁移文件。

相关问题