开发者

How to implement variable dependency versions in Maven3 using _profiles_?

We need to build project with different versions of deps (in this example, Postgres 8 and Postgres 9). Also, our developers have different versions of DBs on their computers.

I'm tried to do something like this:

    <profile>
        <id>postgres9</id>
        <properties>
            <postgres.driver.version>
                9.0-801
            </postgres.driver.version>
        </properties>
    </profile>

    <profile>
        <id>postgres8</id>
        <properties>
            <postgres.driver.version>
                8.3-603
            </postgres.dri开发者_运维技巧ver.version>
        </properties>
    </profile>

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>${postgres.driver.version}</version>
    </dependency>

    <properties>
        <postgres.driver.version>8.3-603</postgres.driver.version>
    </properties>



    mvn clean test -Ppostgres9

But it didn't work. Profile variable is not overriding pom variable at all. Also, I cannot achieve that even with the ~/.m2/settings.xml.

Does anyone know how to do this? Thanks.


We've been trying to do similar things in our projects for quite a while. The only way that consistently works is to pass -Dpostgres.driver.version=8.3-603. For some reason, variables are not interpolated before dependencies are computed.

Oddly enough, it seems to work on some of my projects under Maven 3.0.2. I'm trying to investigate deeper now.


I had the same problem. Moving the version (with the property) from dependency to dependencyManagement in the parent pom solved it for me:

old: pom.xml:

<dependencies>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>${postgres.driver.version}</version>
    </dependency>
</dependencies>

new: pom.xml

<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
</dependency>

parent pom:

  <dependencyManagement>
    <dependencies>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>${postgres.driver.version}</version>
    </dependency>
    </dependencies>
  </dependencyManagement>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜