Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

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

question from:https://stackoverflow.com/questions/2012198/maven-can-i-reference-profile-id-in-profile-definition

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...