How to use profile variables to define final properties values? - spring-boot

In Spring Boot, I know I can define profiles on application.yml. However, it's not clear to me how to achieve the same result as in this pom.xml snippet:
...
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<pucomex.config.redis.host>devhost</pucomex.config.redis.host>
<pucomex.config.redis.port>5678</pucomex.config.redis.port>
</properties>
</profile>
<profile>
<id>tst</id>
<properties>
<pucomex.config.redis.host>tsthost</pucomex.config.redis.host>
<pucomex.config.redis.port>1234</pucomex.config.redis.port>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>2.5.0.Final</version>
<configuration>
<properties>
<!-- properties based on profile variables -->
<pucomex.config.redis.host>${pucomex.config.redis.host}</pucomex.config.redis.host>
<pucomex.config.redis.port>${pucomex.config.redis.port}</pucomex.config.redis.port>
<!-- global properties -->
<elastic.port>9200</elastic.port>
<elastic.rhlc.connect.timeout.ms>5000</elastic.rhlc.connect.timeout.ms>
<elastic.rhlc.socket.timeout.ms>60000</elastic.rhlc.socket.timeout.ms>
</properties>
</configuration>
</plugin>
</plugins>
</build>
...
In other words: I want to have some properties values varying according to each profile and then use them to define the value of another property.

Related

Maven profiles change groupId

We have three profiles and each one needs to set name and groupId for our clients, but my solution shows warnings in Jenkins compilation and haven't transitive dependencys. A part of my pom:
<artifactId>persistenceLib-${proyecto.nombre}</artifactId>
<version>1.0.0</version>
<groupId>${proyecto.groupId}</groupId>
<dependencies>...</dependencies>
<profiles>
<profile>
<id>client1</id>
<activation><activeByDefault>true</activeByDefault></activation>
<properties>
<proyecto.nombre>Client1Lib</proyecto.nombre>
<proyecto.groupId>com.Client1.product</proyecto.groupId>
</properties>
</profile>
<profile>
<id>client2</id>
<activation><activeByDefault>false</activeByDefault></activation>
<properties>
<proyecto.nombre>Client2Lib</proyecto.nombre>
<proyecto.groupId>com.Client2.product</proyecto.groupId>
</properties>
</profile>
<profile>
<id>client3</id>
<activation><activeByDefault>false</activeByDefault></activation>
<properties>
<proyecto.nombre>Client3Lib</proyecto.nombre>
<proyecto.groupId>com.Client3.product</proyecto.groupId>
</properties>
</profile>
</profiles>
¿What is the correct way for a dynamic IDs?

Spring boot change pom configuration with active profile

I was trying to change configuration of the pom based on the active profile (dev, test, qa, prod). but every time it was calling the default one (prod)
I have given the profile info in VM arguments in intellij
arguments : -Dspring.profiles.active=dev
Decleration (in POM.xml)
<profiles>
<profile>
<id>dev</id>
<properties>
<currentRegion>run build_dev</currentRegion>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<currentRegion>run build_test</currentRegion>
</properties>
</profile>
<profile>
<id>qa</id>
<properties>
<currentRegion>run build_qa</currentRegion>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<currentRegion>run build_prod</currentRegion>
</properties>
</profile>
</profiles>
Usage(in POM.xml)
<build>
<plugins>
<plugin>
<executions>
<execution>
<configuration>
<arguments>${currentRegion}</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Every time, this is retuning run build_prod (the default one)
Actually i have combined the spring boot and angular for some testing purpose and i want to run the angular on environment with different environment.ts file , when i hardcode the arguments in pom like run build_dev/test it works file , i want to automate it arguments based on the active profile .
Any Suggestions/Solution is highly appreciated.

Set a property inside a maven profile conditionally, depending on another profile

Is there a way so that, inside a maven profile, I could set a property to one value or another, depending on whether another profile is also active ?
Example: for the sample below,
<profiles>
<profile>
<id>dev</id>
<properties>
<myProp>value-dev</myProp>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<myProp>value-prod</myProp>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<myProp>value-test</myProp>
</properties>
</profile>
</profiles>
if ONLY DEV is active, then I need myProp = value-dev
if DEV and TEST are active, then I need myProp = value-test
How can I achieve this ?
Thanks.

Maven profiles with variable for properties

I am studying MAVEN profiles and i have a question about seting properties with variables. At the moment, i am using the following configuration :
<profile>
<id>Action type D restriction</id>
<activation>
<property>
<name>actionType</name>
<value>D</value>
</property>
</activation>
<properties>
<restriction.actionType>D</restriction.actionType>
</properties>
</profile>
<profile>
<id>Action type W restriction</id>
<activation>
<property>
<name>actionType</name>
<value>W</value>
</property>
</activation>
<properties>
<restriction.actionType>W</restriction.actionType>
</properties>
</profile>
My question is this ; is it possible to somehow use one profile with a variable to do the same job, something along the lines of :
<profile>
<id>Action type restriction</id>
<activation>
<property>
<name>actionType</name>
<value>[D,W]</value>
</property>
</activation>
<properties>
<restriction.actionType>${project.profiles.profile.activation.value}</restriction.actionType>
</properties>
</profile>
Or something along those lines.
Maybe you want something like this
<profiles>
<profile>
<id>Action type restriction</id>
<activation>
<property>
<name>actionType</name>
</property>
</activation>
<properties>
<restriction.actionType>${actionType}</restriction.actionType>
</properties>
</profile>
</profiles>
Thank you Tunaki. That did the trick. Now my setup is this :
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ActionType/>
</properties>
...
<profiles>
<profile>
<id>Action-type profile</id>
<activation>
<property>
<name>actionType</name>
<value>[D,W]</value>
</property>
</activation>
</profile>
</profiles>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>properties.plugin</groupId>
<artifactId>Lazaruss-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<actionType>${actionType}</actionType>
</configuration>
...
</plugin>
</plugins>
</pluginManagement>
</build>
And running it with command :
mvn groupId:artefactId:version:goal -DactionType=W
It sets the variable in my class to W now :)
PS : notice that the variable in my class is also named 'actionType'

how to set a property value according to profile

I'm new to maven and i got this issue when sometimes when i run maven i want to have a property with 1 value and sometimes the other.
I tried to do the following but still something is missing:
<profiles>
<profile>
<id>production</id>
<activation>
<property>
<name>com.sencha.cmd.dir</name>
<value>
${env.SENCHA_PATH}\senchaCmd-${com.sencha.cmd.version}\Sencha\Cmd\${com.sencha.cmd.version}
</value>
</property>
</activation>
</profile>
</profiles>
<properties>
<com.sencha.cmd.dir> ${env.SENCHA_PATH}\senchaCmd- ${com.sencha.cmd.version}\Sencha\Cmd\${com.sencha.cmd.version}</com.sencha.cmd.dir>
my question is how to replace the value of the property com.sencha.cmd.dir according to the availability of the profile?
Hope this is clear enough
It's really simple
<profiles>
<profile>
<id>profile 1</id>
<activation>
...
</activation>
<properties>
<my.property> xxx </my.property>
</properties>
</profile>
<profile>
<id>profile 2</id>
<activation>
...
</activation>
<properties>
<my.property> yyy </my.property>
</properties>
</profile>
</profiles>
and then you can use your my.properties outside, even in an other one properties
<properties>
<my.next.property> abc ${my.property} def </my.next.property>
</properties>

Resources