Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From Version 4.3.2 on change-log file is found twice in classpath #1916

Closed
MichaelZett opened this issue Jun 18, 2021 · 11 comments
Closed

From Version 4.3.2 on change-log file is found twice in classpath #1916

MichaelZett opened this issue Jun 18, 2021 · 11 comments

Comments

@MichaelZett
Copy link

MichaelZett commented Jun 18, 2021

Environment

Liquibase Version: 4.3.2+

Liquibase Integration & Version: gradle 6.8.3, spring boot 2.5.x

Liquibase Extension(s) & Version:

Database Vendor & Version: PostgresQl and H2

Operating System Type & Version: MacOs

Description

After upgrading our spring boot multi-module-gradle-projects from 2.4.7 to 2.5.1 we encountered the issue that the app does not start anymore in IntelliJ with the following error:
"Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error Reading Changelog File: Found 2 files that match classpath:/liquibase/db.changelog-master.xml: file:/Users/[...]/src/main/resources/liquibase/db.changelog-master.xml, file:/Users/[...]/build/resources/main/liquibase/db.changelog-master.xml"

Building and starting the jar with gradle still works.

spring.liquibase.change-log: classpath:/liquibase/db.changelog-master.xml is configured in application.yaml
After downgrading to liquibase 4.3.1 everything works fine.

@molivasdat
Copy link
Contributor

Hi @MichaelZett Thanks for opening this issue. We will add it to the list of issues that are being processed.

@MichaelMyronenko
Copy link

MichaelMyronenko commented Dec 27, 2021

I've faced a similar issue, are there any updates regarding it?
SpringBoot - 2.6.2
liquibase - 4.5.0
But even if I downgrade to liquibase 4.3.0 I get the error anyway. I've fixed it by downgraing to Spring Boot 2.4.9.
My error:
Caused by: liquibase.exception.ChangeLogParseException: Error Reading Changelog File: Found 2 files that match classpath:/db/changelog/db-changelog.xml: file:/home/.../main/src/main/resources/db/changelog/db-changelog.xml, jar:file:/home/.../main/build/libs/main.jar!/db/changelog/db-changelog.xml.
The classpath seems to contain the changelog from the jar and target-directory.

@molivasdat molivasdat added this to To Do in Conditioning++ via automation Dec 30, 2021
@molivasdat
Copy link
Contributor

@MichaelMyronenko We will take a look again.

@MichaelMyronenko
Copy link

MichaelMyronenko commented Jan 4, 2022

@molivasdat The reason was this line in my bootRun task configuration:
sourceResources(sourceSets.main)
I don't know how it worked before the liquibase and SpringBoot upgrade.

@nvoxland
Copy link
Contributor

nvoxland commented Jan 4, 2022

We have been working to improve the way we find files, as well as how it handles unexpected situations. The above behavior is the expected behavior based on your configuration.

By default, gradle and maven should be including your build output/target directory by default in the locations to search for changelog files, and so if you are also specifying that liquibase should look in your sources directory, it's seeing two copies of the changelog files and throwing the (expected) error saying that it's found the file in two separate locations.

The build output is the better one to use, since then if you have any compile-time transformations or whatever it will pick that up like any other "built" code. Removing whatever configuration you have that also includes src/main/resources or sourceSets.main as a classpath or resource path will remove this error.

@nvoxland nvoxland closed this as completed Jan 4, 2022
Conditioning++ automation moved this from To Do to Done Jan 4, 2022
@nvoxland nvoxland removed this from Done in Conditioning++ Jan 4, 2022
@kataggart kataggart added support and removed TypeBug labels Jan 4, 2022
@MichaelZett
Copy link
Author

@MichaelMyronenko Thank you! We had the same configuration in our bootRun-task. After removing it, app starts again in intellij wit the current liquibase version.

@kalpeshraicha
Copy link

kalpeshraicha commented May 2, 2022

We are running into a similar issues when running liquibase unit tests using gradle 7 and liquibase 4.9.1.
We have a parent liquibase changelog file(changelog-test) in our src/test/resources folder that includes xml files (like changelog.xml ) from the src/main/resources folder of our multi-module project.

Replaced our project/module name with "test-project" in the stacktrace below:

Now when we run the unit tests with Lqiuibase 4.9.1, we get the following error:

Caused by: liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: Error Reading Changelog File: Found 2 files that match changelog.xml: file:/C:/test-project/build/resources/main/changelog.xml, jar:file:/C:/test-project/build/libs/test-project-SNAPSHOT.jar!/changelog.xml at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:25) at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:369) at liquibase.Liquibase.lambda$update$1(Liquibase.java:224) at liquibase.Scope.lambda$child$0(Scope.java:180) at liquibase.Scope.child(Scope.java:189) at liquibase.Scope.child(Scope.java:179) at liquibase.Scope.child(Scope.java:158) at liquibase.Liquibase.runInScope(Liquibase.java:2405) at liquibase.Liquibase.update(Liquibase.java:211) at liquibase.Liquibase.update(Liquibase.java:197) at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:314) at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:269) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ... 58 more Caused by: liquibase.exception.SetupException: Error Reading Changelog File: Found 2 files that match changelog.xml: file:/C:/test-project/build/resources/main/changelog.xml, jar:file:/C:/test-project/build/libs/test-project-SNAPSHOT.jar!/changelog.xml at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:371) at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:318) at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:23) ... 71 more Caused by: liquibase.exception.ChangeLogParseException: Error Reading Changelog File: Found 2 files that match changelog.xml: file:/C:/test-project/build/resources/main/changelog.xml, jar:file:/C:/test-project/build/libs/test-project-SNAPSHOT.jar!/changelog.xml at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:111) at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:15) at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:587) at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:363) ... 73 more Caused by: java.io.IOException: Found 2 files that match changelog.xml: file:/C:/test-project/build/resources/main/changelog.xml, jar:file:/C:/test-project/build/libs/test-project-SNAPSHOT.jar!/changelog.xml at liquibase.resource.AbstractResourceAccessor.openStream(AbstractResourceAccessor.java:25) at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:59) ... 76 more

The changelog.xml files is on the classpath from the test-project src and also from the test-project jar itself. This used to work fine in the 3.x version of liquibase. We are a bit late to migrate to 4.x, so we had to jump from the last 3.x version to the latest 4.x version. I see @MichaelMyronenko made some changes in the spring-boot config to fix the issue. Has someone ran into this issue with just using just spring 5.x and gradle 7.x? Any ideas how can we fix this in our project. Thanks !!

@dbyron-sf
Copy link

spinnaker/kork#937 (comment) (and specifically https://github.com/spinnaker/kork/runs/5472596514?check_suite_focus=true) is I think another instance where this happens. That's using gradle 6.8.1, spring boot 2.2.13 and spring 5.2.12 with liquibase 4.8.0. It also happens with spring boot 2.3.12 / spring 5.2.15.

Caused by: liquibase.exception.ChangeLogParseException: Error parsing classpath:classpath:db/healthcheck.yml
	at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:82)
	at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:223)
	at liquibase.Liquibase$1.run(Liquibase.java:194)
	at liquibase.Scope.lambda$child$0(Scope.java:159)
	at liquibase.Scope.child(Scope.java:170)
	at liquibase.Scope.child(Scope.java:158)
	at liquibase.Scope.child(Scope.java:137)
	at liquibase.Liquibase.runInScope(Liquibase.java:1790)
	at liquibase.Liquibase.update(Liquibase.java:183)
	at liquibase.Liquibase.update(Liquibase.java:179)
	at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:322)
	at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:270)
	at com.netflix.spinnaker.kork.sql.migration.SpringLiquibaseProxy.afterPropertiesSet(SpringLiquibaseProxy.kt:65)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790)
	... 107 more
Caused by: java.io.IOException: Found 2 files that match classpath:classpath:db/healthcheck.yml: file:/Users/dbyron/src/spinnaker/salesforce/kork/kork-sql/build/resources/main/db/healthcheck.yml, jar:file:/Users/dbyron/src/spinnaker/salesforce/kork/kork-sql/build/libs/kork-sql.jar!/db/healthcheck.yml
	at liquibase.resource.AbstractResourceAccessor.openStream(AbstractResourceAccessor.java:24)
	at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:25)

Things are fine with liquibase 3.8.9 and 3.10.3, but break with 4.0.0 and 4.1.0. Perhaps curiously, they work again with 4.1.1, 4.2.0, 4.2.1, 4.2.2, 4.3.0, and 4.3.1, and then break with 4.3.2, 4.3.3, 4.3.4, 4.3.5, 4.4.0, 4.4.1, 4.4.2, 4.4.3, 4.5.0, 4.6.0, 4.6.1, 4.6.2, 4.7.0, 4.7.1, 4.8.0, 4.9.0, and 4.9.1. Using 4.9.1, the stack trace is:

Caused by: liquibase.exception.ChangeLogParseException: Error parsing classpath:db/healthcheck.yml
	at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:89)
	at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:369)
	at liquibase.Liquibase.lambda$update$1(Liquibase.java:224)
	at liquibase.Scope.lambda$child$0(Scope.java:180)
	at liquibase.Scope.child(Scope.java:189)
	at liquibase.Scope.child(Scope.java:179)
	at liquibase.Scope.child(Scope.java:158)
	at liquibase.Liquibase.runInScope(Liquibase.java:2405)
	at liquibase.Liquibase.update(Liquibase.java:211)
	at liquibase.Liquibase.update(Liquibase.java:197)
	at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:314)
	at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:269)
	at com.netflix.spinnaker.kork.sql.migration.SpringLiquibaseProxy.afterPropertiesSet(SpringLiquibaseProxy.kt:65)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1858)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1795)
	... 87 more
Caused by: java.io.IOException: Found 2 files that match classpath:db/healthcheck.yml: file:/Users/dbyron/src/spinnaker/kork/kork-sql/build/resources/main/db/healthcheck.yml, jar:file:/Users/dbyron/src/spinnaker/kork/kork-sql/build/libs/kork-sql.jar!/db/healthcheck.yml
	at liquibase.resource.AbstractResourceAccessor.openStream(AbstractResourceAccessor.java:25)
	at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:25)
	... 101 more

@luispollo
Copy link

In case it helps, I have the same behavior with versions 4.3.1 and 4.3.0 which are called out as safe above.

@acezd-finance
Copy link

file- master-changlog.yaml

databaseChangeLog:
- includeAll:
path: src/main/resources/db/changelog/

    error
    liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db.changelog-master.yaml : Could not find directory or directory was empty for includeAll 'src/main/resources/db/changelog/'

@gautammroads
Copy link

I had same issue any possible solution for below ?

2023-10-19 10:15:43,190 ERROR [main] org.springframework.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error Reading Changelog File: Found 2 files that match classpath:/db/changelog/db.changelog-master.xml: file:/C:/Users/gkumar/IdeaProjects/content-kanban-accelerator/target/test-classes/db/changelog/db.changelog-master.xml, file:/C:/Users/gkumar/IdeaProjects/content-kanban-accelerator/target/classes/db/changelog/db.changelog-master.xml at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:121) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) at org.springframework.cloud.contract.wiremock.WireMockTestExecutionListener.applicationContextBroken(WireMockTestExecutionListener.java:120) at org.springframework.cloud.contract.wiremock.WireMockTestExecutionListener.beforeTestClass(WireMockTestExecutionListener.java:43) at org.springframework.test.context.TestContextManager.beforeTestClass(TestContextManager.java:213) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:74) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) Caused by: liquibase.exception.ChangeLogParseException: Error Reading Changelog File: Found 2 files that match classpath:/db/changelog/db.changelog-master.xml: file:/C:/Users/gkumar/IdeaProjects/content-kanban-accelerator/target/test-classes/db/changelog/db.changelog-master.xml, file:/C:/Users/gkumar/IdeaProjects/content-kanban-accelerator/target/classes/db/changelog/db.changelog-master.xml at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:95)

Please help me you find any solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants