Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define maven profiles outside POM

Tags:

maven

pom.xml

Is there a way to define my maven profiles outside POM file but not in .m2/settings.xml?
I want to define them in a separate xml file inside the application (way to work efficiently with maven 2 and 3) because I am using maven 2 and intend to switch to 3 soon.

like image 467
Mahmoud Saleh Avatar asked Nov 16 '11 12:11

Mahmoud Saleh


People also ask

Where are profiles configured in Maven?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom.


3 Answers

Until Maven 2.2.1 you could define your profiles into the profiles.xml file as a separate file but with Maven 3 this opportunity has been removed. The question ist why do you need a separate file for the profiles?

like image 116
khmarbaise Avatar answered Oct 14 '22 10:10

khmarbaise


You may want to go through this maven documentation on build profiles, which describes the types of profiles and how each can be used.

As I see it, profiles cannot be defined outside pom.xml or settings.xml, if you want to use maven 3.

like image 37
Raghuram Avatar answered Oct 14 '22 11:10

Raghuram


<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <build.profile.id>dev</build.profile.id>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <build.profile.id>prod</build.profile.id>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <build.profile.id>test</build.profile.id>
        </properties>
    </profile>
</profiles>

And add a filter

<filters>
   <filter>src/test/resources/${build.profile.id}/config.properties</filter>
</filters>

And add any directory (dev, prod, test)

like image 27
Stéphane GRILLON Avatar answered Oct 14 '22 10:10

Stéphane GRILLON