0

有没有办法在 Maven 分析中对依赖类使用配置文件。

我的问题是,我在一位家长下有两个项目。 product-core-wsproduct-core

product-core-ws是一个令人遗憾的网络服务。现在我想在 product-core 中创建两个配置文件,如下所示

<profiles>
    <profile>
        <id>one</id>

        <dependencies>
            <dependency>
                <groupId>com.fg</groupId>
                <artifactId>product-core-one</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>

    </profile>
    <profile>
        <id>two</id>

        <dependencies>
            <dependency>
                <groupId>com.fg</groupId>
                <artifactId>product-core-two</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>

    </profile>
</profiles> 

当我clean install使用 product-core-ws 时,我需要根据给定配置文件的依赖项

例如,如果我使用

mvn clean install -P 一

,我需要我的war文件中的product-core-one。

我知道我可以直接在我的product-core-ws POM 文件中执行此操作。但我不想在那个 POM 中使用那些。我想通过product-core使用它们。

4

1 回答 1

1

在您的父 POM 中,使用配置文件来设置 Maven 属性的值:

<profiles>
    <profile>
        <id>one</id>
        <properties>
          <product.core.version>product-core-one</product.core.version>
        </properties>
    </profile>
    <profile>
        <id>two</id>
        <properties>
          <product.core.version>product-core-two</product.core.version>
        </properties>
    </profile>
</profiles> 

然后在子模块中使用这个属性:

<dependency>
    <groupId>com.fg</groupId>
    <artifactId>${product.core.version}</artifactId>
    <version>${project.version}</version>
</dependency>
于 2014-06-20T07:26:42.747 回答