Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

database migration plugin - Unable to load classpath resources for sqlFile changesets #963

Closed
acanby opened this issue Mar 31, 2020 · 3 comments

Comments

@acanby
Copy link
Contributor

acanby commented Mar 31, 2020

I'm trying to integrate Spring Batch into my Grails application. The Spring Batch jar supplies per dbms schemas for the required tables, and I have been trying to add this via dbm/liquibase. It seems like something that liquibase supports, and I have seen examples for vanilla Spring Boot/Liquibase that seem to work.

I have a changelog as follows:

databaseChangeLog = {
    changeSet(author: "user", id: "spring-batch-schema-4.2.1.RELEASE", dbms: 'mssql') {
        sqlFile(encoding: "utf8",
                splitStatements: true,
                stripComments: true,
                relativeToChangelogFile: false,
                path: 'classpath:/org/springframework/batch/core/schema-sqlserver.sql'
        )
    }
}

This seems like it should work - but I get the below exception:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-31 13:05:50.125 ERROR --- [  restartedMain] <> o.s.boot.SpringApplication               : Application run failed

liquibase.exception.UnexpectedLiquibaseException: java.io.IOException: File does not exist: 'classpath:/org/springframework/batch/core/schema-sqlserver.sql'
        at liquibase.change.AbstractSQLChange.generateCheckSum(AbstractSQLChange.java:189)
        at liquibase.changelog.ChangeSet.generateCheckSum(ChangeSet.java:255)
        at liquibase.changelog.ChangeSet.toString(ChangeSet.java:807)
        at liquibase.changelog.ChangeLogIterator.createKey(ChangeLogIterator.java:105)
        at liquibase.changelog.ChangeLogIterator.alreadySaw(ChangeLogIterator.java:113)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:77)
        at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:269)
        at liquibase.Liquibase.update(Liquibase.java:198)
        at liquibase.Liquibase.update(Liquibase.java:179)
        at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:317)
        at org.grails.plugins.databasemigration.liquibase.GrailsLiquibase.performUpdate(GrailsLiquibase.groovy:83)

So I did some digging into the exception. A change was added in grails/grails-database-migration@7e46268#diff-9735b2073ff7adabaa25c8f0085a81f2 that overrode the createLiquibase method from the default SpringLiquibase one. It changes the resourceAccessor to the parent of the one used by SpringLiquibase (i.e. removing all Spring awareness).

I'd like to propose changing the resourceAccessor back to the Spring one. I've made the code changes: grails/grails-database-migration@b5ca952. Using this code I can now load the file from the Spring Batch Jar.

If this change was made for a specific reason, I can understand the hesitation to change the implementation for everyone. I'd like to have the option of creating my own GrailsLiquibase instances, but the plugin specifically uses new. Perhaps this could be exposed via a bean factory? Code here: acanby/grails-database-migration@3a1e051.

@andrewcanby-finocomp
Copy link
Contributor

Any thoughts on this one @puneetbehl?

@jdaugherty jdaugherty transferred this issue from grails/grails-database-migration Feb 20, 2025
@jdaugherty jdaugherty changed the title Unable to load classpath resources for sqlFile changesets database migration plugin - Unable to load classpath resources for sqlFile changesets Feb 20, 2025
@jdaugherty
Copy link
Contributor

Any thoughts on this one @puneetbehl?

We have opened #964 to address this, but require the CLA to be signed to proceed.

@jdaugherty
Copy link
Contributor

This is merged, and should be fixed in the next snapshot build.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants