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;
}







38















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)?










share|improve this question































    38















    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)?










    share|improve this question



























      38












      38








      38


      3






      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)?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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
























          3 Answers
          3






          active

          oldest

          votes


















          34














          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.






          share|improve this answer





















          • 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 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



















          14














          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






          share|improve this answer





















          • 3





            Why do i see a snake biting its tail?

            – R.S
            Mar 10 '16 at 12:19



















          3














          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 





          share|improve this answer


























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            34














            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.






            share|improve this answer





















            • 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 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
















            34














            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.






            share|improve this answer





















            • 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 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














            34












            34








            34







            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.






            share|improve this answer















            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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 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














            • 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 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








            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













            14














            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






            share|improve this answer





















            • 3





              Why do i see a snake biting its tail?

              – R.S
              Mar 10 '16 at 12:19
















            14














            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






            share|improve this answer





















            • 3





              Why do i see a snake biting its tail?

              – R.S
              Mar 10 '16 at 12:19














            14












            14








            14







            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






            share|improve this answer















            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







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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














            • 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











            3














            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 





            share|improve this answer






























              3














              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 





              share|improve this answer




























                3












                3








                3







                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 





                share|improve this answer















                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 






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 6 '10 at 20:37

























                answered Jan 6 '10 at 11:05









                Pascal ThiventPascal Thivent

                488k1169601067




                488k1169601067






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python