How to get current maven profile Id in java

Viewed 1043

I am working with selenium webdriver with maven and struggling. I have a set of maven profiles

<profiles>
        <profile>
            <id>demo</id>
            <properties/>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>prod</id>
            <properties/>
        </profile>
    </profiles>

My task is quite simple but i can't find a solution. How can i get and store into variable id of the current profile after i call for example mvn test -P prod? This id is needed later in tests.

1 Answers

I am using this solution: First add property to your profile i.e.

  <profile>
        <id>prod</id>
         <properties>prod<properties>
   </profile>

Than create properties file app.properties with entry

mvnprod=${prod}

read the property file in your code.

Related