'Maven mvn install doesn't run liquibase scripts
everyone! I faced with a problem. I have SpringBoot app with Spring JDBC and liquibase. When I do mvn install my tests failed because, liquibase doesn't run. What is a problem? Liquibase work correctly. When I use liquibase:update or just run an application - everything is fine. I use mySQL db for app and for test too. I even don't know what code you need to look.
In this way I connect to db for test:
@Configuration
public class SpringJdbcConfig {
@Bean
DataSource getDataSource() throws SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setDatabaseName("correct_db");
dataSource.setServerName("localhost");
dataSource.setPort(3306);
dataSource.setUser("bestuser");
dataSource.setPassword("bestuser");
dataSource.setServerTimezone("UTC");
return dataSource;
}
@Bean
public DataSourceTransactionManager transactionManager() throws SQLException {
return new DataSourceTransactionManager(getDataSource());
}
Solution 1:[1]
Running Liquibase through the Maven plugin and through the Spring integration are completely separate ways of running liquibase, even if both are often triggered by a call to Maven.
When you run mvn liquibase:update
you are calling into the liquibase-maven-plugin
you have configured in the <plugins>
section of your pom file. It's running as a particular step of your Maven build, like compile
or package
Alternately, you can configure your Spring application to automatically run the Liquibase update logic when the spring application starts up. You may be starting your Spring app via something in Maven, but it's still Spring that is triggering Liquibase at that point.
If you are not seeing any errors in your application startup about the Liquibase update operation failing, it may be because you don't have Liquibase as a dependency in your actual application. Even if you have the liquibase-maven-plugin plugin configured, you still need to add a
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.10.0</version>
</dependency>
dependency for your application for Liquibase to run within it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nathan Voxland |