Spring boot - disable Liquibase at startup
Asked Answered
V

10

86

I want to have Liquibase configured with my Spring Boot application, so I added dependencies to pom.xml and set the path to master.xml in application.properties. This works fine and Spring Boot runs Liquibase at startup. The problem is that now I want to run Liquibase manually, not at startup of application. Should I completely disable auto-configuration for Liquibase or can I use it and only disable running evaluations at startup?

Vicinity answered 8/6, 2016 at 16:33 Comment(1)
How will you run Liquibase Manually?Loxodromics
M
126

The relevant property name has changed between Spring versions:

  • For Spring 4.x.x: the liquibase.enabled=false application property disables Liquibase.

  • For Spring 5.x.x: the spring.liquibase.enabled=false application property disables Liquibase.


P.S. And for Flyway:

  • Spring 4.x.x: flyway.enabled=false

  • Spring 5.x.x: spring.flyway.enabled=false

Maxson answered 26/3, 2018 at 18:15 Comment(0)
B
39

Add liquibase.enabled=false in your application.properties file

Reference

But if you don't want to use liquibase from application anymore, remove liquibase starter altogether from pom.

Bony answered 9/6, 2016 at 4:7 Comment(1)
This property was migrated to spring.liquibase.enabled.Boulevardier
C
36

If you see on the LiquibaseProperties, there is a prefix like

 prefix = "spring.liquibase"

So, My suggestion is to use

spring.liquibase.enabled=false

It solved my problem with spring boot 2.0.0.RC1

Caitlyncaitrin answered 18/2, 2018 at 5:9 Comment(1)
spring.liquibase.enabled=false solved my problem too Spring 2.7.1Wilhoit
U
18

I faced an issue where I wasn't able to disable Liquibase from properties for some reason, so this is how I disabled Liquibase with @Bean annotation:

@Bean
public SpringLiquibase liquibase() {
  SpringLiquibase liquibase = new SpringLiquibase();
  liquibase.setShouldRun(false);
  return liquibase;
}
Unbridle answered 16/2, 2018 at 16:28 Comment(2)
After this I've received org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'liquibase' availableBosson
This worked for me. It is the only solution that makes a SpringLiquibase bean available for autowiring without running on startup. Remember to put it in a @Configuration class.Choreography
S
16

There is one more programmatic approach.

@EnableAutoConfiguration(exclude = LiquibaseAutoConfiguration.class)

on Application main class

Scabies answered 12/8, 2020 at 6:35 Comment(0)
O
5

Another approach for application.yml:

spring:
  autoconfigure:
    exclude:
      - org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
Originality answered 15/3, 2023 at 14:39 Comment(0)
R
3

If you want to run Liquibase manually, you could use the liquibase maven plugin. Just add something like this to your pom.xml:

  <plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>${liquibase.version}</version>
    <configuration>
      <changeLogFile>src/main/liquibase/master.xml</changeLogFile>
      <propertyFile>src/main/liquibase/liquibase.properties</propertyFile>
      <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
    </configuration>
  </plugin>

You can take a look at the plugin documentation for the configuration details.

And don't use the liquibase support from Spring Boot, as it is only meant to be used in runtime. Just remove the liquibase starter and/or any related dependencies as you'll only need the maven plugin.

Rhododendron answered 8/6, 2016 at 19:30 Comment(3)
The problem with this is that when spring boot finds liquibase on the classpath it will try to execute on startup afaik.Bun
That's why you have to remove the liquibase starter, or any direct liquibase dependency if you added any. If you only have the liquibase maven plugin, liquibase is not in the application classpath.Arlynearlynne
If you disable it during the startup, how will we trigger to run the DB scripts which need to be run ?Loxodromics
M
1

Whilst the documented Spring Boot solution is spring.liquibase.enabled=false, it didn't work for me. To disable liquibase you can also use the following property:

liquibase.shouldRun=false

I passed this as a command line parameter when launching the Spring Boot jar

-Dliquibase.shouldRun=false

see https://docs.liquibase.com/parameters/should-run.html

Millennium answered 18/1, 2023 at 8:48 Comment(0)
I
1

If you have an application-{profile}.yml, you can use:

liquibase:
    enabled: false
Iron answered 18/1, 2024 at 22:11 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Accoucheur
S
0

You can use the spring.liquibase.enabled=true/false

Scourings answered 12/1, 2023 at 7:19 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Exogenous

© 2022 - 2025 — McMap. All rights reserved.