Grails 3 database-migration-plugin initialization error

£可爱£侵袭症+ 提交于 2020-01-02 04:15:11

问题


I recently added database-migration-plugin to my grails 3.0.11 app. The problem is when I try to run-app I get a following error:

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!

Looks like it can't find changelog.xml in my grails-app/migrations folder. My build.gradle file contains:

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

and

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

I also added the following lines in my application.groovy file:

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

I would by very gratefull for any advice how to make database-migration-plugin work properly.

Edit:

I created changelog.xml file using $grails dbm-create-changelog command

I also added to build.gradle (as suggested by $grails plugin-info database-migration command):

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

then I changed it to (following official documentation):

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

and then (as suggested by manual for startup error) I forced liquibase:

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

and

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

The problem still remains: java.lang.IllegalArgumentException: Script text to compile cannot be null!


回答1:


We ran into the same problem when upgrading to Grails 3.

A look into the code of the grails-database-migration plugin made clear that the configuration parameter is changed from a list updateOnStartFileNames to a single value updateOnStartFileName.

So when you change your config from

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

to

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

it should work again.




回答2:


I ran into a similar error. In my case we had some lookup tables where we were populating using a hand crafted script which was included into the main changelog.groovy like:

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

except the file name was incorrect - it should have been 002-... instead. The error is basically the same, but there is no reporting to indicate which included file is not being found/parsed, which is a pain. So if you have manually included files, then look for incorrectly named ones in addition to checking the top-level changelog.groovy or changelog.xml




回答3:


Ok, I finally found a solution. Maybe it will help someone someday. So what I did was simply delete changelog.groovy (i switched from XML to Groovy) file. Then I generated a new one with $grails dbm-create-changelog changelog.groovycommand. As a final step I run $grails dbm-changelog-sync and everything started to work just fine.




回答4:


Make sure:

  1. You have set up the changelog, i.e., the file grails-app/migrations/changelog.xml exists and is valid.

How you do this depends on your situation. The plugin's documentation has a section for how to create the file initially.

  1. Your datasource is set up to use the database that changelog.xml applies to.


来源:https://stackoverflow.com/questions/35132589/grails-3-database-migration-plugin-initialization-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!