liquibase doesn't insert <databaseChangeLog> - maven

I have next pom.xml:
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<id>test-databse-backup</id>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost/db</url>
<username>usr</username>
<password>pswd</password>
<outputChangeLogFile>src/main/resources/db.changelog-databasestructure.xml</outputChangeLogFile>
</configuration>
<goals>
<goal>generateChangeLog</goal>
</goals>
</execution>
...................
So I make database backup by this maven plugin but in result file (db.changelog-databasestructure.xml) I don't see <databaseChangeLog> tag. How to fix this issue?
Thanks in advance.

I think your file src/main/resources/db.changelog-databasestructure.xml shouldn't already exist, So the plugin will create it and insert the databaseChangeLog XML element.
Otherwise, if you would keep your file exist before running the plugin, you have to insert it manually in your XML file.
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
</databaseChangeLog>
Maybe this is a bug.

Related

Maven flyway 4.0.3 - Executing multiple databases as part of a single pom

I read a lot of articles (on flyway and stackoverflow) before deciding to open a question. Mostly the solutions how to setup your pom for executing multiple databases using maven and flyway surround around version 3.0 of flyway.
I have a requirement where I have to connect to multiple schemas using different user accounts and execute totally different SQL's using flyway.
I tried to setup my pom as per article, but it fails to recognize multiple execution tags and also the id. It throws the error message
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.3:migrate (default-cli) on project Flyway_001: org.flywaydb.core.api.FlywayExce
ption: Unable to connect to the database. Configure the url, user and password! -> [Help 1]
My pom looks like
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.flyway</groupId>
<artifactId>Flyway_001</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<A.db.user>A_DB_USER</A.db.user>
<A.db.password>*******</A.db.password>
<A.db.schema>A_DB_SCHEMA</A.db.schema>
<A.db.url>jdbc:oracle:blah..blah</A.db.url>
<B.db.user>B_DB_USER</B.db.user>
<B.db.password>*******</B.db.password>
<B.db.schema>B_DB_SCHEMA</B.db.schema>
<B.db.url>jdbc:oracle:blah..blah</B.db.url>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.3</version>
<executions>
<execution>
<id>flyway-A</id>
<configuration>
<url>${A.db.url}</url>
<user>${A.db.user}</user>
<password>${A.db.password}</password>
<schemas>
<schema>${A.db.schema}</schema>
</schemas>
<table>T_HUB_SCHEMA_VERSION</table>
<baselineOnMigrate>false</baselineOnMigrate>
<locations>
<location>filesystem:src/main/resources/db/A</location>
</locations>
</configuration>
</execution>
<execution>
<id>flyway-B</id>
<configuration>
<url>${B.db.url}</url>
<user>${B.db.user}</user>
<password>${B.db.password}</password>
<schemas>
<schema>${B.db.schema}</schema>
</schemas>
<table>T_HUB_SCHEMA_VERSION</table>
<baselineOnMigrate>false</baselineOnMigrate>
<locations>
<location>filesystem:src/main/resources/db/B</location>
</locations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Has anyone tried connecting to multiple DB's using flyway 4.0? If so will appreciate if someone can give some guidance on whats wrong with my approach.
IDE complained about tags under execution element. Was able to get rid of the complains by specifying the goals tag like so:
<execution>
<id>some-id</id>
<goals>
<goal>migrate</goal>
</goals>
</execution>

Don't Generate Windows Sections Using Appassembler

I am only targeting Solaris when using Appassembler and have this in my pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>question</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>generate-jsw-scripts</id>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
</execution>
</executions>
<configuration>
<repositoryLayout>flat</repositoryLayout>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<target>${project.build.directory}</target>
<configurationDirectory>conf</configurationDirectory>
<daemons>
<daemon>
<id>${project.artifactId}</id>
<mainClass>org.apache.catalina.startup.Bootstrap</mainClass>
<jvmSettings>
<initialMemorySize>512</initialMemorySize>
<maxMemorySize>1024</maxMemorySize>
<extraArguments>
<extraArgument>-Dapp=${project.artifactId}</extraArgument>
<extraArgument>-XX:MaxPermSize=128m</extraArgument>
<extraArgument>-XX:+UseParNewGC</extraArgument>
<extraArgument>-XX:+CMSParallelRemarkEnabled</extraArgument>
<extraArgument>-XX:+UseConcMarkSweepGC</extraArgument>
</extraArguments>
</jvmSettings>
<platforms>
<platform>jsw</platform>
</platforms>
<generatorConfigurations>
<generatorConfiguration>
<generator>jsw</generator>
<includes>
<include>solaris-x86-32</include>
</includes>
<configuration>
<!--Logging-->
<property>
<name>wrapper.logfile.maxsize</name>
<value>10m</value>
</property>
<property>
<name>wrapper.logfile.maxfiles</name>
<value>10</value>
</property>
</configuration>
</generatorConfiguration>
</generatorConfigurations>
</daemon>
</daemons>
</configuration>
</plugin>
</plugins>
</build>
</project>
However, a bat file is still generated and there is a Windows specific section in the generated conf.
Neither are going to stop me running - for instance I can exclude the bat file when using the assembly plugin and I don't think the Windows section will affect me on Solaris.
However, for neatness sake I would rather not generate either in the first place.
Is there a way to prevent them being generated?
EDIT: Added full example pom
EDIT2: I think this is a bug so opened an issue here

JAXB2 Basic Annotate plugin not working with maven cxf-codegen-plugin

I'm using the cxf-codegen-plugin to generate Java classes from wsdl files. I want to add annotations to once of the classes and I specify a Binding File and use the jaxb2-basics-annotate plugin to do so. The generated files don't contain the the annotation specified in the binding file.
Here is the configuration in the pom file
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.4</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/wsdl/QueryJobService.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/QueryJobService.wsdl</wsdlLocation>
<extraargs>
<extraarg>-xjc-Xannotate</extraarg>
</extraargs>
<bindingFiles>
<bindingFile>src/main/resources/wsdl/xsd/job-bindings.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
and here is the binding file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<jaxb:bindings schemaLocation="data.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='resource']">
<annox:annotate target="class">
<annox:annotate annox:class="javax.xml.bind.annotation.XmlSeeAlso" value="model.common.sm.dcp.com.data._1.SimOrder"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
running maven in debug mode doesn't show anything strange. Is it so that cxf-codegen-plugin and jaxb2-basics-annotate don't work together ? Or is there something wrong with my configurations ?
It should work with CXF.
Please make sure that bindings are applied at all. Try to replace annox:annotate with something like <jaxb:class name="FooBar"/> - does it get generated as FooBar?
Also try the new Java Syntax: https://github.com/highsource/jaxb2-annotate-plugin instead of XML.
Finally, I guess you might be missing this attribute on your root jaxb:bindings element:
jaxb:extensionBindingPrefixes="annox"
See this example.
If nothing helps, send me a PR on github.
SO disclaimer: I'm the author of jaxb2-annotate-plugin.

Liquibase on multiple databases

I have already implemented Liquibase with Maven. We are currently using a single database (db2) but now we need to add a new database to the application which will have different objects.
I've seen that i can define a new profile in maven but i couldn't find out how to differentiate which objects is being created on which database.
Is there a solution to this? Can I support 2 different databases with different objects using liquibase?
As you can see in the documentation, you can use two different executions, like this:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.5</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<changeLogFile>PATH_TO_CHANGELOG_1</changeLogFile>
... connection properties ...
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
<execution>
<phase>process-resources</phase>
<configuration>
<changeLogFile>PATH_TO_CHANGELOG_2</changeLogFile>
... connection properties ...
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
The only problem with this approach is that you need two different changelog.xml files, one per database.
Also, you can have preconditions in your changelog file to choose between what changeset will be processed by each database.
For example:
<changeSet id="1" author="bob">
<preConditions onFail="MARK_RAN">
<dbms type="oracle" />
</preConditions>
<comment>Comments should go after preCondition. If they are before then liquibase usually gives error.</comment>
<dropTable tableName="oldtable"/>
</changeSet>
The onFail="MARK_RAN" makes Liquibase skip the changeset but marks it as run, so the next time it will not try again. See the customPrecondition tag in the documentation for more complex preconditions.
You may want to have 2 separate changelogs to manage the two databases, even if they are both used by the same application.
As Arturo says you can have 2 or more execution-nodes, but you must give every execution-node a seperate id.
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.5</version>
<executions>
<execution>
<id>db1-update</id>
<phase>process-resources</phase>
<configuration>
<changeLogFile>src/main/resources/org/liquibase/db1.xml</changeLogFile>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost/db1</url>
<username>..</username>
<password>..</password>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
<execution>
<id>db2-update</id>
<phase>process-resources</phase>
<configuration>
<changeLogFile>src/main/resources/org/liquibase/db2.xml</changeLogFile>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost/db2</url>
<username>...</username>
<password>...</password>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
<execution>
<id>db3-update</id>
<phase>process-resources</phase>
<configuration>
<changeLogFile>src/main/resources/org/liquibase/db3.xml</changeLogFile>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost/db3</url>
<username>...</username>
<password>...</password>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
You can use Preconditions inside changeset or changelog and give conditions according to the database,
<preConditions onFail="WARN">
<dbms type="oracle" />
<runningAs username="SYSTEM"/>
</preConditions>
Like this, you can use precondition tag inside changeset and give conditions according to each database.
Use this link for additions documentation.
Old question but I still answer cause I have the same requirement today, and I am opting for another solution.
I would recommend, if you can, as proposed already in the answers to use seperate changelogs.
But if you want to keep the changelogs unified, as I need for my specific case, I would use labels instead of preconditions to filter changesets to be executed.
<changeSet id="0001:1" author="oz" labels="clickhouse">
<sql>...SOMESQL...</sql>
</changeSet>
<changeSet id="0001:2" author="oz" labels="mongodb">
<ext:createCollection collectionName="myCollection">
...SOMEJSON....
</ext:createCollection>
</changeSet>
This will prevent poluting the databasechangelog of the two databases with the executions of the changesets of the other database.
This will cause problems(for the current release at least 4.6.1) for any liquibase operation using tags, such as rollbackToTag or updateToTag.

Maven: how to use POM elements from within assembly descriptor

I need to assemble several sets of resources. These sets of resources are related to each other. So, I decided to put them all under the same project and use the assembly plugin to achieve my goal.
I have ended with a POM and a descriptor file for each set of resources.
Let's assume that my project is as follows:
src/main/resources/set1 : contains resources for the first set
src/main/resources/set2 : contains resources for the second set
src/main/resources/set3 : contains resources for the third set
descriptor1.xml : the assembly descriptor for the first set
descriptor2.xml : the assembly descriptor for the second set
descriptor3.xml : the assembly descriptor for the thord set
pom.xml
The content of descriptor1.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>set1</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.basedir}/src/main/resources/set1</directory>
</fileSet>
</fileSets>
</assembly>
The content of descriptor2.xml and descriptor3.xml is similar to the content of descriptor1.xml except that set1 (in "/assembly/id" and "/assembly/fieldSets/fieldSet/directory") is replaced by set2 and set3 respectively.
The content of pom.xml is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sample</groupId>
<artifactId>sample.assembler</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<properties>
<maven-assembly-plugin.version>2.4</maven-assembly-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<executions>
<execution>
<id>set1</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor1.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>set2</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor2.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>set3</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor3.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The above config gives the expected result. However, there are a lot of descriptor files to maintain.
I have read in the documentation that descriptor files are interpolated using project properties, POM element values, user properties, ... before being used.
My question is : is there a way to reference the id of the current execution (some thing like project.build.execution.id)? In such a case, all my three descriptors with be replaced by only one file.
Thank you in advance.
I don't think you can achieve what you want within single run.
But you can create a profiles where earch of the profile will define different properties and you can run your build three times with different profiles to get 3 different file sets.
I do use such approach for generating configuration for different environments. I activate the environment profile and the output is the environment configuration. The configuration is generated by single descriptor which is driven by the profile properties.
EDIT:
Here is a workaround using per-execution propeties which may solve your problem. In the moment I'm not entirely sure if these filters will be used for filtering resources only or you can reference them in the assembly itself for defining lets say <finalName> ...
See: http://olafsblog.sysbsb.de/per-assembly-filtering-with-the-maven-assembly-plugin/

Resources