Maven - Can I reference profile id in profile definition?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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)?
java maven-2 maven
add a comment |
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)?
java maven-2 maven
add a comment |
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)?
java maven-2 maven
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)?
java maven-2 maven
java maven-2 maven
edited Nov 16 '18 at 21:49
Rene Knop
1,3613823
1,3613823
asked Jan 6 '10 at 10:23
Ula KrukarUla Krukar
4,896194463
4,896194463
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
.
3
Using${project.activeProfiles[0].id}
worked perfectly for me. You can make sure at least one profile will be active with<activeByDefault>true</activeByDefault>
in one profile's activation block.
– SimonB
Feb 14 '12 at 11:03
2
Same here, ${project.activeProfiles[0].id} worked, maven 3.2
– chrismarx
Jun 13 '16 at 14:56
For some reason, it won't extract a parent pom property; so if, for instance, you activate 2 profiles, one being from a parent, only the current project property will be retrieved.
– ftkg
Dec 8 '16 at 18:08
1
If there's multiple profiles active, this looks likeactiveProfiles[0].id
could to the wrong id.
– antak
Mar 16 '17 at 9:31
@antak It uses the order of the profiles as listed in the pom.xml
– alfonx
Mar 16 '17 at 13:23
add a comment |
As an alternative to ${project.activeProfiles[0].id}
(which doesn't seem to work on older versions of maven), just define a property:
<profile>
<id>dev</id>
<properties>
<profile-id>dev</profile-id>
</properties>
</profile>
Then use ${profile-id}
.
Note: just make sure one is always active by default
3
Why do i see a snake biting its tail?
– R.S
Mar 10 '16 at 12:19
add a comment |
According to PLXUTILS-37, it should be possible to access properties in a List or Map using "Reflection Properties" (see the MavenPropertiesGuide for more about this).
So just try ${project.profiles[0].id}
, ${project.profiles[1].id}
, etc.
If this doesn't work (I didn't check if it does), I'd use profile activation based on a system property as described in Introduction to build profiles and use that property in the filter. Something like that:
<profile>
<id>profile-profileId1</id>
<activation>
<property>
<name>profile</name>
<value>profileId1</value>
</property>
</activation>
<build>
<filters>
<filter>src/main/filters/${profile}.properties</filter>
</filters>
// rest of the profile
</profile>
To activate this profile, you would type this on the command line:
mvn groupId:artifactId:goal -Dprofile=profileId1
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2012198%2fmaven-can-i-reference-profile-id-in-profile-definition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
.
3
Using${project.activeProfiles[0].id}
worked perfectly for me. You can make sure at least one profile will be active with<activeByDefault>true</activeByDefault>
in one profile's activation block.
– SimonB
Feb 14 '12 at 11:03
2
Same here, ${project.activeProfiles[0].id} worked, maven 3.2
– chrismarx
Jun 13 '16 at 14:56
For some reason, it won't extract a parent pom property; so if, for instance, you activate 2 profiles, one being from a parent, only the current project property will be retrieved.
– ftkg
Dec 8 '16 at 18:08
1
If there's multiple profiles active, this looks likeactiveProfiles[0].id
could to the wrong id.
– antak
Mar 16 '17 at 9:31
@antak It uses the order of the profiles as listed in the pom.xml
– alfonx
Mar 16 '17 at 13:23
add a comment |
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
.
3
Using${project.activeProfiles[0].id}
worked perfectly for me. You can make sure at least one profile will be active with<activeByDefault>true</activeByDefault>
in one profile's activation block.
– SimonB
Feb 14 '12 at 11:03
2
Same here, ${project.activeProfiles[0].id} worked, maven 3.2
– chrismarx
Jun 13 '16 at 14:56
For some reason, it won't extract a parent pom property; so if, for instance, you activate 2 profiles, one being from a parent, only the current project property will be retrieved.
– ftkg
Dec 8 '16 at 18:08
1
If there's multiple profiles active, this looks likeactiveProfiles[0].id
could to the wrong id.
– antak
Mar 16 '17 at 9:31
@antak It uses the order of the profiles as listed in the pom.xml
– alfonx
Mar 16 '17 at 13:23
add a comment |
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
.
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
.
edited Jun 26 '18 at 9:11
peterh
6,394155271
6,394155271
answered Apr 28 '11 at 16:47
alfonxalfonx
4,4524055
4,4524055
3
Using${project.activeProfiles[0].id}
worked perfectly for me. You can make sure at least one profile will be active with<activeByDefault>true</activeByDefault>
in one profile's activation block.
– SimonB
Feb 14 '12 at 11:03
2
Same here, ${project.activeProfiles[0].id} worked, maven 3.2
– chrismarx
Jun 13 '16 at 14:56
For some reason, it won't extract a parent pom property; so if, for instance, you activate 2 profiles, one being from a parent, only the current project property will be retrieved.
– ftkg
Dec 8 '16 at 18:08
1
If there's multiple profiles active, this looks likeactiveProfiles[0].id
could to the wrong id.
– antak
Mar 16 '17 at 9:31
@antak It uses the order of the profiles as listed in the pom.xml
– alfonx
Mar 16 '17 at 13:23
add a comment |
3
Using${project.activeProfiles[0].id}
worked perfectly for me. You can make sure at least one profile will be active with<activeByDefault>true</activeByDefault>
in one profile's activation block.
– SimonB
Feb 14 '12 at 11:03
2
Same here, ${project.activeProfiles[0].id} worked, maven 3.2
– chrismarx
Jun 13 '16 at 14:56
For some reason, it won't extract a parent pom property; so if, for instance, you activate 2 profiles, one being from a parent, only the current project property will be retrieved.
– ftkg
Dec 8 '16 at 18:08
1
If there's multiple profiles active, this looks likeactiveProfiles[0].id
could to the wrong id.
– antak
Mar 16 '17 at 9:31
@antak It uses the order of the profiles as listed in the pom.xml
– alfonx
Mar 16 '17 at 13:23
3
3
Using
${project.activeProfiles[0].id}
worked perfectly for me. You can make sure at least one profile will be active with <activeByDefault>true</activeByDefault>
in one profile's activation block.– SimonB
Feb 14 '12 at 11:03
Using
${project.activeProfiles[0].id}
worked perfectly for me. You can make sure at least one profile will be active with <activeByDefault>true</activeByDefault>
in one profile's activation block.– SimonB
Feb 14 '12 at 11:03
2
2
Same here, ${project.activeProfiles[0].id} worked, maven 3.2
– chrismarx
Jun 13 '16 at 14:56
Same here, ${project.activeProfiles[0].id} worked, maven 3.2
– chrismarx
Jun 13 '16 at 14:56
For some reason, it won't extract a parent pom property; so if, for instance, you activate 2 profiles, one being from a parent, only the current project property will be retrieved.
– ftkg
Dec 8 '16 at 18:08
For some reason, it won't extract a parent pom property; so if, for instance, you activate 2 profiles, one being from a parent, only the current project property will be retrieved.
– ftkg
Dec 8 '16 at 18:08
1
1
If there's multiple profiles active, this looks like
activeProfiles[0].id
could to the wrong id.– antak
Mar 16 '17 at 9:31
If there's multiple profiles active, this looks like
activeProfiles[0].id
could to the wrong id.– antak
Mar 16 '17 at 9:31
@antak It uses the order of the profiles as listed in the pom.xml
– alfonx
Mar 16 '17 at 13:23
@antak It uses the order of the profiles as listed in the pom.xml
– alfonx
Mar 16 '17 at 13:23
add a comment |
As an alternative to ${project.activeProfiles[0].id}
(which doesn't seem to work on older versions of maven), just define a property:
<profile>
<id>dev</id>
<properties>
<profile-id>dev</profile-id>
</properties>
</profile>
Then use ${profile-id}
.
Note: just make sure one is always active by default
3
Why do i see a snake biting its tail?
– R.S
Mar 10 '16 at 12:19
add a comment |
As an alternative to ${project.activeProfiles[0].id}
(which doesn't seem to work on older versions of maven), just define a property:
<profile>
<id>dev</id>
<properties>
<profile-id>dev</profile-id>
</properties>
</profile>
Then use ${profile-id}
.
Note: just make sure one is always active by default
3
Why do i see a snake biting its tail?
– R.S
Mar 10 '16 at 12:19
add a comment |
As an alternative to ${project.activeProfiles[0].id}
(which doesn't seem to work on older versions of maven), just define a property:
<profile>
<id>dev</id>
<properties>
<profile-id>dev</profile-id>
</properties>
</profile>
Then use ${profile-id}
.
Note: just make sure one is always active by default
As an alternative to ${project.activeProfiles[0].id}
(which doesn't seem to work on older versions of maven), just define a property:
<profile>
<id>dev</id>
<properties>
<profile-id>dev</profile-id>
</properties>
</profile>
Then use ${profile-id}
.
Note: just make sure one is always active by default
edited May 20 '14 at 21:56
answered Jan 31 '14 at 21:49
Mike RMike R
2,65832237
2,65832237
3
Why do i see a snake biting its tail?
– R.S
Mar 10 '16 at 12:19
add a comment |
3
Why do i see a snake biting its tail?
– R.S
Mar 10 '16 at 12:19
3
3
Why do i see a snake biting its tail?
– R.S
Mar 10 '16 at 12:19
Why do i see a snake biting its tail?
– R.S
Mar 10 '16 at 12:19
add a comment |
According to PLXUTILS-37, it should be possible to access properties in a List or Map using "Reflection Properties" (see the MavenPropertiesGuide for more about this).
So just try ${project.profiles[0].id}
, ${project.profiles[1].id}
, etc.
If this doesn't work (I didn't check if it does), I'd use profile activation based on a system property as described in Introduction to build profiles and use that property in the filter. Something like that:
<profile>
<id>profile-profileId1</id>
<activation>
<property>
<name>profile</name>
<value>profileId1</value>
</property>
</activation>
<build>
<filters>
<filter>src/main/filters/${profile}.properties</filter>
</filters>
// rest of the profile
</profile>
To activate this profile, you would type this on the command line:
mvn groupId:artifactId:goal -Dprofile=profileId1
add a comment |
According to PLXUTILS-37, it should be possible to access properties in a List or Map using "Reflection Properties" (see the MavenPropertiesGuide for more about this).
So just try ${project.profiles[0].id}
, ${project.profiles[1].id}
, etc.
If this doesn't work (I didn't check if it does), I'd use profile activation based on a system property as described in Introduction to build profiles and use that property in the filter. Something like that:
<profile>
<id>profile-profileId1</id>
<activation>
<property>
<name>profile</name>
<value>profileId1</value>
</property>
</activation>
<build>
<filters>
<filter>src/main/filters/${profile}.properties</filter>
</filters>
// rest of the profile
</profile>
To activate this profile, you would type this on the command line:
mvn groupId:artifactId:goal -Dprofile=profileId1
add a comment |
According to PLXUTILS-37, it should be possible to access properties in a List or Map using "Reflection Properties" (see the MavenPropertiesGuide for more about this).
So just try ${project.profiles[0].id}
, ${project.profiles[1].id}
, etc.
If this doesn't work (I didn't check if it does), I'd use profile activation based on a system property as described in Introduction to build profiles and use that property in the filter. Something like that:
<profile>
<id>profile-profileId1</id>
<activation>
<property>
<name>profile</name>
<value>profileId1</value>
</property>
</activation>
<build>
<filters>
<filter>src/main/filters/${profile}.properties</filter>
</filters>
// rest of the profile
</profile>
To activate this profile, you would type this on the command line:
mvn groupId:artifactId:goal -Dprofile=profileId1
According to PLXUTILS-37, it should be possible to access properties in a List or Map using "Reflection Properties" (see the MavenPropertiesGuide for more about this).
So just try ${project.profiles[0].id}
, ${project.profiles[1].id}
, etc.
If this doesn't work (I didn't check if it does), I'd use profile activation based on a system property as described in Introduction to build profiles and use that property in the filter. Something like that:
<profile>
<id>profile-profileId1</id>
<activation>
<property>
<name>profile</name>
<value>profileId1</value>
</property>
</activation>
<build>
<filters>
<filter>src/main/filters/${profile}.properties</filter>
</filters>
// rest of the profile
</profile>
To activate this profile, you would type this on the command line:
mvn groupId:artifactId:goal -Dprofile=profileId1
edited Jan 6 '10 at 20:37
answered Jan 6 '10 at 11:05
Pascal ThiventPascal Thivent
488k1169601067
488k1169601067
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2012198%2fmaven-can-i-reference-profile-id-in-profile-definition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown