0

Maven プロファイリングで依存クラスにプロファイルを使用する方法はありますか。

私の問題は、1 つの親の下に 2 つのプロジェクトがあることです。 product-core-wsおよびproduct-core

product-core-ws嘆かわしい Web サービスです。次のように、product-core 内に 2 つのプロファイルを作成したいと思います。

<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> 

product-core-ws の場合clean install、指定されたプロファイルに従って依存関係が必要です

たとえば、私が使用する場合

mvn clean install -P one

、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 に答える