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>
Related
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.
This question already has answers here:
Activating a Child Profile from a Parent Profile
(2 answers)
Closed 5 years ago.
I have two pom's an aggregate and a child, the child has a profile I would like to be activated based upon a property set in the parents profile eg.
parent pom.xml
<profiles>
<profile>
<id>emptyModules</id>
<modules>
<module>child</module>
</modules>
<properties>
<emptyModules>true</emptyModules>
</properties>
</profile>
</profiles>
The child has two profiles one with some modules the other without
<profiles>
<profile>
<id>modules</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
</profile>
<profile>
<id>emptyModules</id>
<activation>
<property>
<name>emptyModules</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
When I activate the parent emptyModules profile I want the child emptyModule profile to activate, however the default profile is used instead! Any ideas?
You can activate profiles based on properties:
<profiles>
<profile>
<activation>
<property>
<name>someprop</name>
</property>
</activation>
...
</profile>
</profiles>
This could be used to activate a parent and child profile at once.
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'
I would like to be able to use an environment variable if it's set or a default fallback value that I set in pom.xml similar to ${VARIABLE:-default} in bash. Is it possible? Something like:
${env.BUILD_NUMBER:0}
I wasn't really satisfied with the accepted approach, so I simplified it a little.
Basically set a default property in the normal properties block, and only override when appropriate (instead of an effective switch statement):
<properties>
<!-- Sane default -->
<buildNumber>0</buildNumber>
<!-- the other props you use -->
</properties>
<profiles>
<profile>
<id>ci</id>
<activation>
<property>
<name>env.buildNumber</name>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<buildNumber>${env.buildNumber}</buildNumber>
</properties>
</profile>
</profiles>
You could use profiles to achieve this:
<profiles>
<profile>
<id>buildnumber-defined</id>
<activation>
<property>
<name>env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<buildnumber>${env.BUILD_NUMBER}</buildnumber>
</properties>
</profile>
<profile>
<id>buildnumber-undefined</id>
<activation>
<property>
<name>!env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<buildnumber>0</buildnumber>
</properties>
</profile>
</profiles>
A bit more verbose than bash...
Trying to get a properties to be set based upon whether a user's OS is windows 10+ or below.
However whenever I enable the command inside the OS tags, the properties are not set. Comment them out however and then the properties are set again.
Code below:
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
<version>(,10.0)</version>
</os>
</activation>
<properties>
<ChromeWebDriverLocation>${basedir}${file.separator}driver${file.separator}win32${file.separator}chrome${file.separator}chromedriver.exe</ChromeWebDriverLocation>
<IEWebDriverLocation>${basedir}${file.separator}driver${file.separator}win32${file.separator}ie${file.separator}IEDriverServer.exe</IEWebDriverLocation>
<SkipIETests>false</SkipIETests>
<SkipEdgeTest>true</SkipEdgeTest>
</properties>
</profile>
<profile>
<id>windows10Edge</id>
<activation>
<os>
<family>windows</family>
<version>[10.0,)</version>
</os>
</activation>
<properties>
<ChromeWebDriverLocation>${basedir}${file.separator}driver${file.separator}win32${file.separator}chrome${file.separator}chromedriver.exe</ChromeWebDriverLocation>
<EdgeWebDriverLocation>${basedir}${file.separator}driver${file.separator}win64${file.separator}edge${file.separator}MicrosoftWebDriver.exe</EdgeWebDriverLocation>
<SkipIETests>true</SkipIETests>
<SkipEdgeTest>false</SkipEdgeTest>
</properties>
</profile>
<profiles>