Maven profiles change groupId - maven

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?

Related

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.

How to acess a property under specific profile in Maven

I have 2 pom files - ParentPOM and ChildPOM. I want to Access property1 in ParentPOM in ChildPOM. I know this can be done by making ParentPOM as the parent for ChildPOM and use ${property1}. But property1 is defined in 2 profiles - trunk and release and I always want to get the value of property1 defined in release. How do I do that? ie:- In the below example, I want the value should be 0.0.2 and not 0.0.1 when I Access property1 in ChildPOM.
Note:I cannot modify ParentPOM
<project>
<modelVersion>x.x.x</modelVersion>
<artifactId>ParentPOM</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>ParentPOM</name>
<profiles>
<profile>
<id>trunk</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<property1>0.0.1</property1>
</properties>
</profile>
<profile>
<id>release</id>
<properties>
<property1>0.0.2</property1>
</properties>
</profile>
</profiles>
</project>
<project>
<modelVersion>x.x.x</modelVersion>
<parent>
<groupId>com.temp</groupId>
<artifactId>ParentPOM</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>ChildPOM</artifactId>
<version>2.0.0</version>
<packaging>pom</packaging>
<name>ChildPOM</name>
<profiles>
<profile>
<id>trunk</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<property1>x.x.x</property1>
</properties>
</profile>
<profile>
<id>release</id>
<properties>
<property1>y.y.y</property1>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.xxx</groupId>
<artifactId>xxx</artifactId>
<version>${property1}</version>
</dependency>
</dependencies>
</project>
Introduce a property "releaseProperty1" in your parent pom. Use this property both for the definition of "property1" in the profile "release" and for your use cases in the child pom.
There is one cleanish solution, but it all depends on the why... why do you want this?
The solution is: removing the release-profile from child and execute Maven like this: mvn <goal> -Prelease,!trunk, i.e enable release profile and disable trunk profile.
To confirm this solution, run mvn help:evaluate -Dexpression=property1 -Prelease,!trunk

bring pom's profile value on jsp

I have dev,local, prod profiles on pom.xml
<profile>
<id>local</id>
<properties>
<env>local</env>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
is it possible to bring this profile value on jsp?
I want to split some area of jsp with different compile option
<c:choose>
<c:when test="${isFlag =='loc'}">
<c:when test="${isFlag =='dev'}">
</>

Using profiles in Netbeans and Maven multimodule project to build for Windows and Linux

In a NetBeans "workspace" for Java there are several projects (all dirs are on same level):
Main
MainExecutable (contains the main(String[] args) method for debugging)
JNILibrary (only available for Linux)
10 further projects
And I am trying to make it debuggable on Windows by providing "stubs" (just some empty methods) source code for Windows through the profile in JNILibrary\pom.xml:
<groupId>com.example</groupId>
<artifactId>jnilibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.example.test</groupId>
<artifactId>Main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Main/pom.xml</relativePath>
</parent>
<build>
<sourceDirectory>${src.dir}</sourceDirectory>
</build>
<profiles>
<profile>
<id>windows</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<src.dir>src/windows/java</src.dir>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<src.dir>src/linux/java</src.dir>
</properties>
</profile>
</profiles>
After that I am able to select Set Configuration -> linux or Set Configuration -> Windows, when I right-click on the JNILibrary project in NetBeans.
Unfortunately, when I try to debug the MainExecutable project - it still (builds and) starts the Linux version - and fails to start on my Windows PC.
Could someone please point into right direction on how to solve my problem?
Here is an excerpt from Main\pom.xml:
<groupId>com.example.test</groupId>
<artifactId>Main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Main</name>
<modules>
<module>../MainExecutable</module>
<module>../jnilibrary</module>
<module>../10/further/modules</module>
</modules>
And here an excerpt from MainExecutable\pom.xml:
<parent>
<groupId>com.example.test</groupId>
<artifactId>Main</artifactId>
<relativePath>../Main</relativePath>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>MainExecutable</artifactId>
<packaging>jar</packaging>
As you wrote, move the 2 profiles to Main/pom.xml and add to both of them new property jnilibrary.src.dir
<profiles>
<profile>
<id>windows</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<jnilibrary.src.dir>src/windows/java</src.dir>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jnilibrary.src.dir>src/linux/java</src.dir>
</properties>
</profile>
</profiles>
and use that property in JNILibrary\pom.xml
<build>
<sourceDirectory>${jnilibrary.src.dir}</sourceDirectory>
</build>
You can use the OS Name to activate the profile:
<build>
<sourceDirectory>${src.dir}</sourceDirectory>
</build>
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<name>Windows</name>
</os>
</activation>
<properties>
<src.dir>src/windows/java</src.dir>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<name>Linux</name>
</os>
</activation>
<properties>
<src.dir>src/linux/java</src.dir>
</properties>
</profile>
</profiles>

Maven Profile Variable web project not working

I´ve got a modular maven project that contains 3 modules. In one of those (WEB), the profile variable is not being recognized as an environment variable, but it takes que real name of it, as shown below:
<Principal POM>
<Module App-core>
<Module ejb>
<Module web>
At the principal POM, there are 3 profiles thas have the same profile propertie with distinct values:
<profile1>
<environment>value1</environment>
<profile2>
<environment>value2</environment>
<profile3>
<environment>value3</environment>
That variable is used as classifier variable for dependencies, as below:
<dependency>
<groupId>com.test</groupId>
<artifactId>app-core</artifactId>
<version>1.0.0</version>
<classifier>${environment}</classifier>
</dependency>
At maven compile phase, only at Web Project, it doen´t change the variable name with the variable value.
Any help?
The tags profile1 profile2 profile3 don't enable the replacing property. To do this you have change your parent pom in this way
<project>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>profile1</id>
<properties>
<environment>value1</environment>
</properties>
</profile>
<profile>
<id>profile2</id>
<properties>
<environment>value2</environment>
</properties>
</profile>
<profile>
<id>profile3</id>
<properties>
<environment>value2</environment>
</properties>
</profile>
</profiles>
</project>
Now you have to run mvn install -P profile1 yourProjectName
I've resolved the issue.
I've replicated the dependencies into profiles. I had multiples dependencies
This is the code to the profile1
<profile>
<id>profile1</id>
<properties>
<environment>value1</environment>
</properties>
<dependency>
<groupId>com.test</groupId>
<artifactId>app-core</artifactId>
<version>1.0.0</version>
<classifier>${environment}</classifier>
</dependency>
</profile>
This is the code to the profiles2
<profile>
<id>profile2</id>
<properties>
<environment>value2</environment>
</properties>
<dependency>
<groupId>com.test</groupId>
<artifactId>app-core</artifactId>
<version>1.0.0</version>
<classifier>${environment}</classifier>
</dependency>
</profile>
And this the code is to the profile3
<profile>
<id>profile3</id>
<properties>
<environment>value3</environment>
</properties>
<dependency>
<groupId>com.test</groupId>
<artifactId>app-core</artifactId>
<version>1.0.0</version>
<classifier>${environment}</classifier>
</dependency>
</profile>

Resources