Closed kulemeevag closed 2 years ago
I was able to get this working with by doing the following:
classpath
dependency in the buildscript
block of your build.gradle file.liquibase
block to load the application.yml file. I did need to add a path to the file before it was found. I put this line at the beginning of my liquibase block, but I think you could also put it inside the main
block.username props.spring.datasource.username
. For some reason, calling props.getProperty didn't work for me.Does this solve your problem?
I was able to get this working with by doing the following:
- I added the snakeYaml as a
classpath
dependency in thebuildscript
block of your build.gradle file.- I added a line to the my
liquibase
block to load the application.yml file. I did need to add a path to the file before it was found. I put this line at the beginning of my liquibase block, but I think you could also put it inside themain
block.- I changed the url, driver, etc. to lines like this:
username props.spring.datasource.username
. For some reason, calling props.getProperty didn't work for me.Does this solve your problem?
@stevesaliman, thanks for your answer. Yes, it worked if add
buildscript {
dependencies {
classpath group: 'org.yaml', name: 'snakeyaml', version: '1.25'
}
}
Maybe it will help someone: For parameter changeLogFile
need use props.spring.liquibase."change-log"
But now I have 3 problems:
spring:
liquibase:
change-log: classpath:migrations/migrate.xml
But when I use liquibase plugin I have error liquibase.exception.ChangeLogParseException: classpath:migrations/migrate.xml does not exist
. Resolved by adding props.spring.liquibase."change-log".replace('classpath:','src/main/resources/')
. Not sure if this is a good solution.
If you want to use a classpath resource, you need to have liquibaseRuntime sourceSets.main.output
in your dependencies block, and you need to make the liquibase task you're trying to use dependent on processResources with something like update.dependsOn processResources
so that the file is in the right place when Liquibase runs.
I think your larger issue is the fact that you're trying to replicate what Spring Boot does when it processes yaml files in your build script. Spring has a lot of code to load the right files in the right order, making all the variable substitutions for you.
There are two ways I could see to possibly address the issue. You could make sure all the liquibase properties you need are in the application-whatever.yml file, then you wouldn't have the merging problem. You could also use the Gradle Properties Plugin to define profile specific properties for Gradle and skip loading the application.yml file altogether. Neither is a perfect solution, but they'd work.
Out of curiosity, if you're using Spring Boot, why not just let Spring Boot run liquibase for you when the application starts? That way you don't need to worry about Gradle properties, and Spring will just use the application*.yml files in the normal manner.
Plugin I use, then want check migration. For example rollback case. Yes, then Spring Boot start application, he run migration.
Thanks, for your answer
I need get props from my application.yml file and use for plugin in build.gradle. How can I achieve this?
I tried use, but nothing:
def props = new org.yaml.snakeyaml.Yaml().load( new File("application.yml").newInputStream() )
Gradle can't resolve Yaml. org.yaml:snakeyaml:1.25 included by spring-boot-starter-parent. I try add org.yaml:snakeyaml:1.25 to my dependency manual. Not fixed error.P.S.: liquibase: 3.8.6 liquibase-plugin: 2.0.4 spring-boot-starters: web, data-jpa