Maven的轮廓和工件版本 [英] Maven profile and artifact version

查看:154
本文介绍了Maven的轮廓和工件版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有行家多模块项目富:

Assume we have maven multimodule project "Foo":

Foo
|-web-module-war
  |-dependency-jar

有用于定义两个配置文件的 moduleC

There are two profiles defined for moduleC:

    <profile>
        <id>poll-some-external-service</id>
        <properties>
            <dependency-jar.poll.configured>true</dependency-jar.poll.configured>
        </properties>
    </profile>
    <profile>
        <id>produce-some-product</id>
        <properties>
            <dependency-jar.poll.configured>false</dependency-jar.poll.configured>
        </properties>
    </profile>

现在我们运行两个版本:

Now we run two builds:


  1. MVN清洁套装-P轮询一些-外部服务

  2. MVN清洁套装-P生产,一些产品

首先建立农产品以下项目:

First build produce following artifacts:

web-module-war-1.0.0-poll.war
dependency-jar-1.0.0-poll.war

其次建立农产品以下项目:

Second build produce following artifacts:

web-module-war-1.0.0-produce.war
dependency-jar-1.0.0-produce.war

这意味着战争文件包含Web应用程序的基础上选择个人资料以不同的方式其中工程。

This means that war file contains web application which works in a different way based on selected profile.

命名是基于在父pom.xml中如下配置:

Naming is based on the following configuration in the parent pom.xml:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <jarName>${project.build.finalName}${foo.build.info}</jarName>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <warName>${project.build.finalName}${foo.build.info}</warName>
        </configuration>
    </plugin>

如何部署这些文物到的Nexus? -poll / -produce部分部署过程中剥离。这意味着我们有相同版本的两个不同的应用程序,但我们只能部署其中的一个

How can I deploy these artifacts into Nexus? -poll/-produce part is stripped during deployment. This means we have two different applications of the same version but we can deploy only one of them

感谢

推荐答案

而不是更改名称使用分类

Instead of changing the name use a classifier

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <classifier>poll</classifier>
    </configuration>
</plugin>

您的POM配置文件应类似于下面的例子。请注意,您必须使用该配置文件也改变依赖关系。

Your profile for the pom should look similar to the following example. Note that you have to change the dependencies by using the profile too.

    <profile>
        <id>poll</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <classifier>poll</classifier>
                    </configuration>
                </plugin>
            </plugins>
            <dependencies>
                <dependency>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>dependency-jar</artifactId>
                    <classifier>poll</classifier>
                </dependency>
            </dependencies>
        </build>
    </profile>

这篇关于Maven的轮廓和工件版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆