【问题标题】:Maven profile and artifact versionMaven 配置文件和工件版本
【发布时间】:2016-01-05 16:35:41
【问题描述】:

假设我们有 maven 多模块项目“Foo”:

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

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>

现在我们运行两个构建:

  1. mvn clean package -P poll-some-external-service
  2. mvn clean package -P 生产一些产品

第一次构建产生以下工件:

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

第二次构建产生以下工件:

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

这意味着 war 文件 包含基于所选 配置文件 以不同方式工作的 Web 应用程序。

命名基于父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 部分在部署期间被剥离。这意味着我们有两个相同版本的不同应用程序,但我们只能部署其中一个

谢谢

【问题讨论】:

    标签: java maven build continuous-integration nexus


    【解决方案1】:

    使用分类器代替更改名称

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

    您的 pom 配置文件应类似于以下示例。请注意,您也必须使用配置文件来更改依赖关系。

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

    【讨论】:

    • 我不喜欢引入分类器的想法。事实上我已经尝试过了(见我原来的问题stackoverflow.com/questions/32992406/…)。
    • 据我了解,分类器应该用于附加一些工件(例如 java 文档、源代码),例如复制工件。我不确定这在我的情况下是否正确使用
    • 您正在更改 jar/war 的内容,因此您需要一些分类器来确定要在其他项目中使用哪个 jar/war,否则 maven 无法正确进行版本控制跨度>
    猜你喜欢
    • 2012-05-17
    • 2015-05-23
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 2011-04-22
    相关资源
    最近更新 更多