简体   繁体   English

Liquibase与Maven

[英]Liquibase with Maven

I want to launch Liquibase for a Java EE - project, so I can make easy DB-Updates at the production server. 我想为Java EE-项目启动Liquibase,因此我可以在生产服务器上轻松进行DB-Update。

I have problems understanding what do i need for the start. 我在理解开始时需要什么有困难。 I read at many examples that you need to download the liquibase-core, extract it and put the .jar to your PATH. 我读过许多示例,您需要下载liquibase-core,将其解压缩并将.jar放入您的PATH。 I think that this is not needed for Maven. 我认为Maven不需要这样做。

To include the dependencies (the core and the liquibase-maven-plugin) at the pom.xml should be enough/ should be the same? 要在pom.xml中包含依赖项(核心和liquibase-maven-plugin)应该足够/应该相同吗?

    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-maven-plugin</artifactId>
        <version>2.0.5</version>
        <type>maven-plugin</type>
    </dependency>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
        <version>2.0.5</version>
    </dependency>

This is probably a silly question, but I have hardly experience with Maven and none with Liquibase. 这可能是一个愚蠢的问题,但是我几乎没有Maven的经验,也没有Liquibase的经验。

In my opinion you was a little bit confused with the method to add liquibase to your project. 我认为您对将liquibase添加到项目中的方法有些困惑。 We shouldn't understand liquibase as a simple dependency, it is a maven plugin . 我们不应该将liquibase理解为一个简单的依赖项,它是一个maven插件

I think that could be clearly if you see some of my config files to understand better what I'm referring to: 我认为,如果您看到一些配置文件以更好地理解我所指的内容,则可能会很清楚:

pom.xml: pom.xml:

<build>
    <sourceDirectory>src</sourceDirectory>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <excludes>
                        <exclude>**/test/*</exclude>
                        <exclude>**/test/me/*</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>2.9.2-01</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-batch</artifactId>
                        <version>2.4.3-01</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.5.3</version>
                <configuration>
                    <propertyFile>src/tv/be/persistence/liquibase/code/dsv.properties</propertyFile>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>update</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

dsv.properties: dsv.properties:

driver: com.mysql.jdbc.Driver
classpath: [local_path]/mysql-connector-java/5.1.41/mysql-connector-java-5.1.41.jar
url: jdbc:mysql://[db_server_ip]:3306/schema_db
username: user1
password: masterkey
changeLogFile: src/tv/be/persistence/liquibase/code/master.xml
contexts=local

Take attention to dsv.properties file. 注意dsv.properties文件。 Each liquibase context needs one proper properties file like that to specify schema and changelog. 每个liquibase上下文都需要一个适当的属性文件来指定模式和变更日志。 That provides the ability to work with different environments ( dsv,local,test,pro,... ) in real time and apply the changes only in the environment/context specified. 这样就可以实时使用不同的环境( dsv,local,test,pro,... ),并且仅在指定的环境/上下文中应用更改。

Project folder: 项目文件夹:

在此处输入图片说明

That structure is very clean for our team because we have all changelog organized by version and functions, procedures and views separated from root database changes but the greatest thing here is that every change has the issue/task code associated and we can trace everything so easily. 这种结构对我们的团队来说非常干净,因为我们所有的变更日志都是按照版本和功能,过程和视图来组织的,并且与根数据库变更分开,但是最重要的是,每个变更都具有关联的问题/任务代码,因此我们可以轻松地跟踪所有内容。

mvn: mvn:

To execute liquibase plugin you should execute that mvn command: 要执行liquibase插件,您应该执行该mvn命令:

mvn liquibase:update

You also can update automatically the database because of liquibase pom's plugin param: 由于liquibase pom的插件参数,您还可以自动更新数据库:

<execution>
   <phase>process-resources</phase>
   <goals>
       <goal>update</goal>
   </goals>
</execution>

We use liquibase in several projects and without deeping in the pros of use it, have database version control, history, common logic of diferents projects and maintenance as mandatory for our development team. 我们在多个项目中使用liquibase,并且没有深入使用它的优点 ,但数据库版本控制,历史记录,不同项目的通用逻辑和维护是我们开发团队的必备条件。

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

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