Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 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)?

See Question&Answers more detail:os

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...