Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change maven dependency's version by using different maven profiles

I have two projects, project A is depending on project B, so normally, I'd have the following section in my projectA/pom.xml:

<dependency>
   <artifactId>projectB</artifactId>
   <groupId>blabla</groupId>
   <version>version1</version>
</dependency>

What I am trying to achieve is very straight forward, does maven profile allow me to do anything like:

if(profileA) {
    <version>version1</version>
}
else {
    <version>version2</version>
}
like image 964
Shengjie Avatar asked May 11 '12 14:05

Shengjie


1 Answers

Yes, this can be done (put activeByDefault to whichever profile you need to be default).

<dependency>
    <artifactId>projectB</artifactId>
    <groupId>blabla</groupId>
    <version>${dependency.version}</version>
</dependency>
...
<profiles>
    <profile>
        <id>first</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>            
        <properties>
            <dependency.version>1.2.3</dependency.version>
        </properties>
    </profile>
    <profile>
        <id>second</id>
        <properties>
            <dependency.version>2.3.4</dependency.version>
        </properties>
    </profile>
</profiles>
like image 97
Andrew Logvinov Avatar answered Oct 22 '22 13:10

Andrew Logvinov