简体   繁体   English

我如何对依赖项使用Maven分析

[英]How can I use maven profiling to a dependant

Is there a way to use profile to a dependent class in maven profiling. 有没有一种方法可以在Maven分析中对个人类使用概要文件。

My problem is that, I have two projects under one parent. 我的问题是,我在一个父项下有两个项目。 product-core-ws and product-core . product-core-wsproduct-core

product-core-ws is a deplorable web service .Now I want to create two profiles inside product-core like following product-core-ws是一个令人遗憾的Web服务 。现在,我想在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> 

and when I clean install the product-core-ws I need the dependency according to the given profile 当我clean install product-core-ws时,我需要根据给定的配置文件进行依赖

For example if I use 例如,如果我使用

mvn clean install -P one mvn全新安装-P一

, I need the product-core-one inside my war file. ,我需要在war文件中添加product-core-one。

I know that I can do this directly in my product-core-ws POM file. 我知道我可以直接在product-core-ws POM文件中执行此操作。 But I don't want to use those in that POM. 但是我不想在该POM中使用那些。 I want to use them through product-core . 我想通过product-core使用它们。

In your parent POM, use profiles to set the value of a Maven property: 在您的父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> 

Then use this property in the child module: 然后在子模块中使用此属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM