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.

1

Best Answer


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.Driverclasspath: [local_path]/mysql-connector-java/5.1.41/mysql-connector-java-5.1.41.jarurl: jdbc:mysql://[db_server_ip]:3306/schema_dbusername: user1password: masterkeychangeLogFile: src/tv/be/persistence/liquibase/code/master.xmlcontexts=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.