Liquibase Parameters not being read correctly in changelog - maven

I am attempting to get some parameters from liquibase.properties read into my changelog file but not having much success.
I am basing my work on the following stack overflow question: Liquibase changelog parameters in liquibase.properties
The following is my liquibase.properties file:
driver:com.mysql.jdbc.Driver
changeLogFile:src/main/resources/changelog/db.changelog-master.xml
url:jdbc:mysql://localhost:3306/localDB
username:root
password:superSecretPassword
verbose:true
parameter.schemaName:dev_tableName
I have a few different liquibase.properties files for different profiles on maven. The following is in my changelog file and the part I am having difficulty with.
<property name="schema" value='${schemaName}' />
The problem is the property is always coming back as the literal value "${schemaName}" and not "dev_tableName". The reason I need this is because there is a reference to another schema in my changelog that changes from environment to environment.
For example dev_tableName and sys_tableName, and I would rather have several liquibase.properties files for each environment as opposed to a full set of changelogs for each environment. Any help would be appreciated, thanks.
Edit:
If it matters- I am building this via Maven with the following settings:
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase-version}</version>
<configuration>
<propertyFile>${liquibase.properties.path}</propertyFile>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java/</outputDirectory>
<processor>com.querydsl.apt.hibernate.HibernateAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<liquibase.properties.path>${project.basedir}/src/main/resources/dev/liquibase.properties</liquibase.properties.path>
<env>dev</env>
<versionNumber>${env}-${project.version}</versionNumber>
</properties>
</profile>

For anyone else having the same problem I ended up solving this issue by using Maven resource plugin instead. Link can be found here: https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

Related

Maven wildfly deployment with multiple servers (standalone)

in my environment I have two wildfly server where I want to deploy with the wildfly-maven-plugin.
The servers differ in the name dev01 and dev02 but have the same port 9993 and username and password.
My understanding is that the wildfly-maven-plugin support only single server deployment.
If the problem are not big enough we use a module/submodule structure where the war file will be build in a submodule.
I'm using two profiles wildfly-deploy-dev01 and wildfly-deploy-dev02.
<profiles>
<profile>
<id>wildfly-deploy-dev01</id>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>wildfly-deploy-dev02</id>
<build>
[...]
<profiles>
In the main module I skipped it.
In the war submodule:
<profiles>
<profile>
<id>wildfly-deploy-dev01</id>
<build>
<finalName>${project.artifactId}-v1.0</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<id>wildfly-credentials<id>
<hostname>dev01.example.com</hostname>
<protocol>remote+https</protocol>
<port>9993</port>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>wildfly-deploy-dev01</id>
<build>
[same as above for hostname dev02.example.com]
</profiles>
First I was thinking everthing works fine but then I found out that only the last server will be deployed.
mvn wildfly:deploy -P wildfly-deploy-dev01,wildfly-deploy-dev02
I played around by setting the configration after the execution tag without success. It looks that the second profile overwrite the first one.
Futher I hardcoded the finalname because the parsedVersion is not parsed.
<finalName>${project.artifactId}-v${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</finalName>
At the moment I'm lost with Maven. Has anybody an idea how I can deploy with the plugin on two servers?
Thanks,
Markus
Ways which I tried:
https://github.com/tsotzolas/wildfly_maven_plugins_examples/blob/master/deployToMultiplesServer/pom.xml
wildfly-maven-plugin not deploying when multiple profiles selected
Cannot access parsedVersion value in pom properties
You should be able to do this in a single profile with different executions. There shouldn't be a need to multiple profiles.
<profiles>
<profile>
<id>wildfly-deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<id>wildfly-credentials<id>
<protocol>remote+https</protocol>
<port>9993</port>
</configuration>
<executions>
<execution>
<id>deploy-dev1</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<hostname>dev01.example.com</hostname>
</configuration>
</execution>
<execution>
<id>deploy-dev2</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<hostname>dev02.example.com</hostname>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profiles>
With this you'd just have to do mvn clean install -Pwildfly-deploy.

Maven: How to print the current profile on the console?

I'm trying to print the current profile that is active running a build of a Maven Project.
I'm using the maven-antrun-plugin in order to print messages on the console, in combination with a property that refers to the current profile.
I have tried the following properties:
${project.activeProfiles[0].id}
${project.profiles[0].id}
But in both cases it prints the "string" as it is written, without resolving the variable.
This is my test:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>current active profile: ${project.activeProfiles[0].id}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
But this is the result that I obtain:
main:
[echo] current active profile: ${project.activeProfiles[0].id}
Any suggestion will be appreciated.
Thanks.
The maven-help-plugin offers what you need. It has an active-profiles goal.
You can add it to your pom or even call it from the command line (include it in your maven build call). The How can I tell which profiles are in effect during a build? section of the Maven profile introduction page will show you how. In short:
mvn help:active-profiles
As this does not work for you (see comments) here is another solution:
I think the active profiles (there can be more than one!) are not propagated as available variables - but properties are.
So set a custom property in the profile section and use that, like
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<myProfile>default</myProfile>
</properties>
</profile>
<profile>
<id>debug</id>
<activation>
<property>
<name>debug</name>
</property>
</activation>
<properties>
<myProfile>debug</myProfile>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>current active profile: ${myProfile}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
you can add the maven-help-plugin in your pom to display always the active profile
<build>
<plugins>
<!-- display active profile in compile phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>show-profiles</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
source: https://www.mkyong.com/maven/maven-profiles-example

gmaven plugin: how to set property in pom.xml for external groovy script

I'm running an external groovy script via gmaven plugin in pom.xml.
The external script is say 'myscript.groovy'.
I want to provide some parameters/arguments to myscript.groovy via the maven pom.xml [i.e. inside the plugin 'gmaven-plugin' execution]; but unable to do so..
I've tried using in ; but not sure how to retrieve its values in the groovy script. Simply calling properties.get is not giving the property value.
Snap of pom file:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
Not sure how to retrieve the value of 'installation.dir' property in 'configure.groovy' script.
Any hint in this regard will be useful.. thanks
There are two ways you can bind and retrieve properties. One would be through plugin-specific properties.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<installation.dir>${installation.dir}</installation.dir>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
These would be retrieved in the script like project.properties['installation.dir'].
GMaven isn't maintained anymore (I was the last maintainer). If you want to use versions of Groovy newer than 2.0.0, have a look at GMavenPlus. Here's the equivalent POM:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<bindPropertiesToSeparateVariables>false</bindPropertiesToSeparateVariables>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<scripts>
<script>file:///${pom.basedir}/src/main/groovy/configure.groovy</script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Retrieval in this case would be like properties['installation.dir']. I know the file:/// is annoying. I've removed the requirement for that in the next release.
For GMaven or GMavenPlus, if you choose the plugin properties approach, you will need to set the value elsewhere either with something like this in your project POM
<properties>
<installation.dir>C:\someDir</installation.dir>
</properties>
Or include it in your call like mvn -Dinstallation.dir=C:\someDir
The other option is to bind to project level properties directly. You would put it in your project level properties or in your call, like mentioned above, and don't include <properties> in the plugin <configuration>. If you go this route, you'd access in your script by project.properties['installation.dir'] for either GMaven or GMavenPlus (also take out <bindPropertiesToSeparateVariables> for GMavenPlus in this case).
If this doesn't work for you, try renaming installation.dir to something like installationDir. I can't remember offhand if periods were problematic.

Maven not detecting existing file

I'm writing a pom file to conditionally checkout or update a subdirectory from git. However, it always does a clean checkout. I'm doing this to wrap CI scripts around existing projects without having to change them.
Here's the code (slightly censored, and with the update ommitted):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>standard-php-project</artifactId>
<version>1.0</version>
<properties>
<git.project>Test/Project</git.project>
<git.project.checkout.directory>${basedir}/src/php/main/${git.project}</git.project.checkout.directory>
<git.project.checkout.exists.file>${git.project.checkout.directory}/.git/index</git.project.checkout.exists.file>
</properties>
<scm>
<connection>scm:git:ssh://server/git/${git.project}</connection>
</scm>
<profiles>
<profile>
<id>scm-checkout</id>
<activation>
<file>
<missing>${git.project.checkout.exists.file}</missing>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<id>echo-missing-file</id>
<phase>generate-sources</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<echos>
<echo>Couldn't find ${git.project.checkout.exists.file}</echo>
</echos>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<id>scm-generate-sources-phase</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${git.project.checkout.directory}</checkoutDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- And another profile for when the file exists, not shown for brevity -->
</profiles>
</project>
I've run mvn compile which tells me the file it tests for, done ls -l on the file to verify it exists, and then run again. For some reason, the test fails.
Help!
Profiles are determined prior to applying properties from the pom
<missing>${git.project.checkout.exists.file}</missing> won't work from the value in your pom.xml
If it was provided on commandline then I believe it would work
Otherwise you need to include the value directly
<missing>/src/php/main/Test/Project/.git/index</missing>
See also Maven profile by user defined property

jmeter plugin maven test-jar

Hi I'm trying to automate my JMeter load balancing test with the jmeter-maven-plugin from lazerycode. My JMeter tests uses premade junit class files which I pack into a test-jar with the maven-jar-plugin. But before the jar file is installed on my local maven repository maven starts the jmeter test. Is there a way I can install the test-jar so I can use it as a dependency in the jmeter plugin? below you'll find my jmeter plugin configuration.
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>jmeter-test</id>
<phase>integration-test</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>groupID</groupId>
<artifactId>artifactID</artifactId>
<version>${project-version}</version>
<type>test-jar</type>
</dependency>
</dependencies>
<configuration>
<propertiesUser>
<current.protocol>http</current.protocol>
<current.dns>localhost</current.dns>
<current.port>8088</current.port>
</propertiesUser>
<testFilesDirectory>${basedir}/src/jmeter/tests/</testFilesDirectory>
<ignoreResultErrors>true</ignoreResultErrors>
<ignoreResultFailures>true</ignoreResultFailures>
<useOldTestEndDetection>true</useOldTestEndDetection>
</configuration>
</plugin>
thx
Put the test jar into a different module, then make the project with the jmeter plugin dependent on that module. You will then be able to install the tests then execute them in jmeter in a single Maven invocation.
I solved this problem by using an activation profile :-
<profiles>
<profile>
<id>ptest</id>
<activation>
<property>
<name>ptest</name>
</property>
</activation>
<build>
<resources>
<resource>
<directory>src/jmeter</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<useOldTestEndDetection>true</useOldTestEndDetection>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Using this approach you can install once, not using the profile, and then run subsequently with the profile turned on.

Resources