8

I have two modules (editor and engine) that work with a common database. For deployment of scripts I want to use liquibase. I do not want to duplicate the same scripts in two places, and I want to manage them in one place. To do this, I created a separate module (database-structure) that only contains my scripts and the parameter spring .liquibase.change-log=classpath:db/changelog/db.changelog-master.xml. I have add this module (database-structure) as a dependency to my other modules. The final structure is as follows (classes are omitted for compactness):

D:\PROJECTS\MY-PROJECT
├───database-structure
│   │   pom.xml
│   │
│   └───src
│       ├───main
│       │   ├───java
│       │   └───resources
│       │       │   application.properties
│       │       │
│       │       └───db
│       │           └───changelog
│       │               │   db.changelog-master.xml
│       │               │
│       │               └───1.0
│       │                       db.changelog-1.0.xml
│       │                       metadata_create.sql
│       │                       metadata_insert_data.sql
│       │                       metadata_rollback.sql
│       │
│       └───test
│           └───java
├───editor
│   │   pom.xml
│   │
│   └───src
│       ├───main
│       │   ├───java
│       │   └───resources
│       │       │   application.properties
│       │       │
│       │       └───META-INF
│       │               spring.factories
│       │
│       └───test
│           ├───java
│           │   └───ru
│           │       └───test
│           │           └───editor
│           │               └───EditorControllerTest.java   
│           │
│           └───resources
│                   application.yml
│       
│
└───engine
    │   pom.xml
    │
    └───src
        ├───main
        │   ├───java
        │   └───resources
        │           application.yml
        │
        └───test
            ├───java
            └───resources

But, When I start tests in editor, for example (EditorControllerTest.java), I get error, that Liquibase not found:

Caused by: java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)

But, I set spring.liquibase.change-log parameter in application.properties in database-structure module. Why it is ignored?

If I specify this option in the editor module, everything works. How to collect all of the logic work with the Liquibase in the same place in database-structure module?

All_Safe
  • 1,339
  • 2
  • 23
  • 43
  • Centralized config is helpful. Please take a look at [here](https://spring.io/guides/gs/centralized-configuration/) – Ebrahim Pasbani Jun 22 '19 at 18:54
  • here you can read all about property files and how to specify multiple ones. https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files – Toerktumlare Jun 22 '19 at 19:24

2 Answers2

2

But, I set spring.liquibase.change-log parameter in application.properties in database-structure module. Why it is ignored?

At runtime, as with any resources or classes, the first application.properties found on the classpath at the root (/) will be picked up the others will be ignored.

Puce
  • 37,247
  • 13
  • 80
  • 152
0

I've kept changelogs files in shared configuration: see Change working directory for gradle multi-module project

And then refer to them in every needed sub-modules: Applying Liquibase migrations for integration tests on a multi module gradle project

Grigory Kislin
  • 16,647
  • 10
  • 125
  • 197