Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - Can I reference profile id in profile definition?

I've set profiles in a pom.xml, like shown as follows:

<profile> <id><em>profileId1</em></id>     <build>         <filters>             <filter>src/main/filters/<em>profileId1</em>.properties</filter>         </filters> // rest of the profile  </profile> <profile> <id><em>profileId2</em></id>     <build>         <filters>             <filter>src/main/filters/<em>profileId2</em>.properties</filter>         </filters> // rest of the profile </profile> 

Question:

Is there any way to extract this piece from all the profiles, so that there is no need to repeat it for every profile (and possibly misspell it)?

like image 450
Ula Krukar Avatar asked Jan 06 '10 10:01

Ula Krukar


People also ask

How do I run a specific profile in Maven?

Open Maven settings. m2 directory where %USER_HOME% represents the user home directory. If settings. xml file is not there, then create a new one. Add test profile as an active profile using active Profiles node as shown below in example.

Can Maven profile be defined in POM xml?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.

Is it possible to add library dependencies inside a profile?

Or dependencies may be pulled from different repositories based upon the JDK version used. Just put the dependency for the release profile inside the profile declaration itself and do the same for debug .

Which of the build profile is defined in Maven?

A - A Build profile is a set of configuration values which can be used to set or override default values of Maven build. B - Using a build profile, you can customize build for different environments such as Production v/s Development environments.


1 Answers

With maven 2.2.1 and later, I was able to get the ID of the first active profile using:

${project.activeProfiles[0].id} 

Of course this fails if there is not a least one active profile.

Using the

${project.profiles[0].id} 

as suggested by Pascal did not work for me.

Hint: While investigating this, I really started to love mvn help:evaluate.

like image 50
alfonx Avatar answered Oct 02 '22 09:10

alfonx