2

I want to launch Liquibase for a Java EE - project, so I can make easy DB-Updates at the production server.

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. I think that this is not needed for Maven.

To include the dependencies (the core and the liquibase-maven-plugin) at the pom.xml should be enough/ should be the same?

    <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.

user1338413
  • 2,471
  • 8
  • 29
  • 36
  • Example: - http://stackoverflow.com/questions/10794169/lock-oracle-database-before-running-the-delete-load-data-scripts/10804663#10804663 – Mark O'Connor Jan 22 '13 at 19:52
  • I read at http://www.liquibase.org/manual/maven "You can find the all the versions of the Liquibase-core and Maven plugins in the central repository by going here." Seems like i totally misunderstood it. Thought I need both(the core and the maven-plugin). But according to the example i dont need the liquibase-core at all, if I use the liquibase-maven-plugin? – user1338413 Jan 22 '13 at 22:24
  • 2
    Maven pulls in liquibase-core automatically as a dependency. Checkout the POM file: http://search.maven.org/#artifactdetails|org.liquibase|liquibase-maven-plugin|2.0.5|maven-plugin – Mark O'Connor Jan 23 '13 at 05:30
  • Thanks for the explanation and for the link. Good to know that site, that should be helpful for the future as well. Thanks a lot :) – user1338413 Jan 23 '13 at 09:00

1 Answers1

4

In my opinion you was a little bit confused with the method to add liquibase to your project. We shouldn't understand liquibase as a simple dependency, it is a maven plugin .

I think that could be clearly if you see some of my config files to understand better what I'm referring to:

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:

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. Each liquibase context needs one proper properties file like that to specify schema and changelog. 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.

Project folder:

enter image description here

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:

To execute liquibase plugin you should execute that mvn command:

mvn liquibase:update

You also can update automatically the database because of liquibase pom's plugin param:

<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.

bishop
  • 360
  • 5
  • 21