简体   繁体   English

在多模块项目中使用 Liquibase

[英]Using Liquibase in multi module project

I have two modules ( editor and engine ) that work with a common database.我有两个模块( editorengine )可与通用数据库一起使用。 For deployment of scripts I want to use liquibase .对于脚本的部署,我想使用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 .为此,我创建了一个单独的模块( database-structure ),它只包含我的脚本和参数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.我已将此模块( database-structure )添加为我其他模块的依赖项。 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:但是,当我在editor中开始测试时,例如( EditorControllerTest.java ),我收到错误,即找不到 Liquibase:

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.但是,我在database-structure模块的application.properties中设置spring.liquibase.change-log参数。 Why it is ignored?为什么会被忽略?

If I specify this option in the editor module, everything works.如果我在editor模块中指定此选项,一切正常。 How to collect all of the logic work with the Liquibase in the same place in database-structure module?如何在database-structure模块的同一位置收集所有与Liquibase的逻辑工作?

But, I set spring.liquibase.change-log parameter in application.properties in database-structure module. 但是,我在数据库结构模块的application.properties中设置了spring.liquibase.change-log参数。 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. 与任何资源或类一样,在运行时,将拾取在类路径的根目录( / )上找到的第一个application.properties,其余的将被忽略。

I've kept changelogs files in shared configuration: see Change working directory for gradle multi-module project我将更改日志文件保存在共享配置中:请参阅更改 gradle 多模块项目的工作目录

And then refer to them in every needed sub-modules: Applying Liquibase migrations for integration tests on a multi module gradle project然后在每个需要的子模块中引用它们:在多模块 gradle 项目上应用 Liquibase 迁移进行集成测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM