mackesmilian
mackesmilian

Reputation: 123

Liquibase: java.nio.file.InvalidPathException: Illegal char <:> at index when not in classpath

My project structure is as follows:

project
|___project-web
|___project-service
|___project-database

project-web is a spring boot project where the application class is. Project-database is not a spring boot project, but just contains a build.gradle and our liquibase changelogs. Now, in project-web I have integration tests that need to run the liquibase changelogs. When I copy my changelogs into project-web/src/test/resources and set the change-log parameter as change-log: classpath:db/db-migrations/changelog.xml this works as expected.

However, for obvious reasons I want to avoid copying the chanelogs when they're already present in the project. For this I tried setting the change-log parameter as change-log: file:../project-database/db-migrations/changelog.xml which results in this exception: java.nio.file.InvalidPathException: Illegal char <:> at index 4: file:../project-database/db-migrations/v2024.07.1/2024.07.16-initial.xml.

So the path itself is correct, liquibase can find the files, but it fails with said exception unless I copy the very same files to my test/resources folder. I also tried arbitrarily changing the order of my changelog files to see if it was one file, but the exception is always the exact same.

EDIT: I am not 100% sure I did it correctly, but I tried following Nikos' advice: In build.gradle of project-database I added:

sourceSets {
main {
    resources {
        srcDir 'db-migrations'
    }
}}

Then I added a dependency in project-web on project-database and changed the liquibase parameter to change-log: classpath:project-database/db-migrations/changelog.xml.

However, this doesn't work and the test fails with Caused by: liquibase.exception.ChangeLogParseException: ERROR: The file 'classpath:project-database/db-migrations/changelog.xml' was not found.

Did I do something incorrectly?

Upvotes: 0

Views: 145

Answers (1)

Juliyanage Silva
Juliyanage Silva

Reputation: 2699

You can add liquibase.properties file in project level and then define the changelog file inside it like:

# Enter the path for your changelog file.
changeLogFile=src/main/resources/db/changelog-master.yaml

This would let liquibase know where to find the file. When you do not give this it will look in the project's resources folder

Upvotes: 0

Related Questions