简体   繁体   English

maven-release-plugin不适用于多模块POM

[英]maven-release-plugin does not work for multi-module POMs

Plugin version: 2.0 插件版本: 2.0

I am trying to use the maven-release-plugin to set the version of the parent POM and all modules. 我正在尝试使用maven-release-plugin来设置父POM和所有模块的版本。

Using the following parent POM: 使用以下父POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>uk.co.mycompany</groupId>
    <artifactId>myProject</artifactId>
    <version>latest-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>My Project</name>

    <modules>
        <module>../../subPom1</module>
        <module>../../subPom2</module>
            <module>../../subPom3</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.0</version>
                <executions>
                    <execution>
                        <phase>clean</phase>
                        <id>set-release-versions</id>
                        <configuration>
                            <developmentVersion>1.1.8</developmentVersion>
                            <autoVersionSubmodules>true</autoVersionSubmodules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

When running mvn clean install -DskipTests -Pdeploy , the configuration to run the plugin on the clean phase is totally ignored and the build is made using the value "latest-SNAPSHOT". 运行mvn clean install -DskipTests -Pdeploy ,将完全忽略在clean阶段运行插件的配置,并使用值“latest-SNAPSHOT”进行构建。

I was expecting it to pick up the value "1.1.8" from the plugin configuration. 我期待它从插件配置中获取值“1.1.8”。

Each child POM is equivalent to: 每个孩子POM相当于:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>uk.co.mycompany</groupId>
        <artifactId>myProject</artifactId>
        <version>latest-SNAPSHOT</version>
        <relativePath>../../System/build/parentPom.xml</relativePath>
    </parent>

    ...

</project>

Why is the configuration ignored? 为什么忽略配置?

Edit #1: Filesystem structure as requested: 按要求编辑#1:文件系统结构:

/
 |- system
 |  |
 |  |- build
 |      |
 |      |-parentPOM file
 |
 |- business
 |     |
 |     | - childPOM1
 |     | - childPOM2
 |- client
 |     | - childPOM3
 |     | - childPOM4

Ignore the .../... in the SSCCE - I have obfuscated the true values to describe the problem generically. 忽略SSCCE中的...... / ... - 我已经模糊了真正的值来描述这个问题。

Edit #2: I have moved the definition to <pluginManagement> as advised but the problem remains the same (not using plugin, no feedback to console): 编辑#2:我已按照建议将定义移至<pluginManagement> ,但问题仍然相同(不使用插件,没有反馈到控制台):

<pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.0</version>
                    <configuration>
                        <developmentVersion>1.1.8</developmentVersion>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

You forgot to set the goal of the plugin. 你忘了设置插件的目标。 You configured the parameter needed for the update-versions goal but you told maven only to execute the plugin in the clean phase, but not which goal of the plugin. 您配置了更新版本目标所需的参数,但您告诉maven只在清洁阶段执行插件,而不是插件的目标。 So it does nothing at all. 所以它什么都不做。

Check the maven log when you try a mvn clean it should only show: 当你尝试mvn clean时检查maven日志它应该只显示:

[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ test ---

When you change your config to: 当您将配置更改为:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.0</version>
            <executions>
                <execution>
                    <phase>clean</phase>
                    <id>set-release-versions</id>
                    <goals><goal>update-versions</goal></goals>
                    <configuration>
                        <developmentVersion>1.1.8</developmentVersion>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The goal update-versions is called in the clean phase of maven. 目标更新版本在maven的清洁阶段调用。

[INFO] --- maven-release-plugin:2.0:update-versions (set-release-versions) @ bdd ---

Not sure if this will solve all your problems but this will force maven to execute the plugin in the clean phase like expected. 不确定这是否会解决您的所有问题,但这将迫使maven在清洁阶段执行插件,如预期的那样。

However the release plugin needs a lot of special settings (like a scm connection) when used for only changing the version. 但是,当用于仅更改版本时,发布插件需要许多特殊设置(如scm连接)。 So I suggest to use the versions-maven-plugin 所以我建议使用versions-maven-plugin

 <build>
    <plugins>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>set</goal>
                    </goals>
                    <phase>clean</phase>
                    <configuration>
                        <newVersion>1.1.8</newVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

In the end, I gave up. 最后,我放弃了。

That Stack Overflow et all is littered with unanswered questions just like this one, and that the plugin documentation fails to provide usage examples in POM format, tells me everything that I need to know about this plugin. Stack Overflow等所有这些问题都充满了未解决的问题,并且插件文档无法提供POM格式的使用示例,告诉我关于此插件需要了解的所有内容。

My workaround was to set the parent POM's version to "latest-SNAPSHOT" and introduce a property called <myproject.release.version>, which I used everywhere that I wanted to print the release number. 我的解决方法是将父POM的版本设置为“latest-SNAPSHOT”并引入一个名为<myproject.release.version>,的属性<myproject.release.version>,我在任何地方都使用它来打印版本号。

In particular, I wanted to print the release number in the WAR file's manifest. 特别是,我想在WAR文件的清单中打印版本号。 I did so as below: 我这样做如下:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
            <configuration>
                    <archive>
                          <manifest>
                               <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                           <manifestEntries>
                                    <Implementation-Version>${myproject.release.version}</Implementation-Version>
                                </manifestEntries>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                        <configuration>
                            <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                            <filters>
                                <filter>${project.parent.basedir}/filter/${webapp.filter}.properties</filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
 </plugin>

Using the above configuration, I drop the release number, as a Maven property, into my manifest. 使用上面的配置,我将版本号作为Maven属性删除到我的清单中。

In my application, I pick it up from there and draw it on the screen. 在我的应用程序中,我从那里拿起它并在屏幕上绘制它。

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

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