Maven Release执行提交附加文件

问题描述 投票:7回答:3

我正在使用Maven发布插件的preparationGoals配置选项来转换其他文件以反映正在发布的项目的版本。这很好用。

问题是,在执行提交时,插件显式指定只应包含pom.xml文件,从而使我的其他文件不受控制:

[INFO] Executing: /bin/sh -c cd /Users/jw/dev/Test && git commit --verbose -F /var/folders/w0/hr1h_7h50f3_pwd_nrk9l808000195/T/maven-scm-114713951.commit pom.xml library/pom.xml sample/pom.xml

有没有办法让我覆盖这种行为并指定要包含在提交中的其他文件或整数?

(我也需要completionGoals的这种行为,我已经配置了同样的转换)

maven maven-plugin maven-3 maven-release-plugin
3个回答
4
投票

你能用maven-scm-plugin吗?添加运行scm:checkin目标的插件执行以提交所需的文件。将它绑定到将在运行preparationGoals时执行的阶段(如果您指定一个或多个阶段作为该元素的值),或直接在scm:checkin中包含preparationGoals目标。


2
投票

我还需要提交一些额外的文件(由Maven Replacer插件更改)。我是通过以下方式完成的:

首先我配置Maven Release plugin来执行其他目标:

<plugin>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
        <preparationGoals>-Prelease -DreplacerVersion="${releaseVersion}" clean replacer:replace scm:checkin verify</preparationGoals>
        <completionGoals>-Prelease -DreplacerVersion="${developmentVersion}" clean replacer:replace scm:checkin verify</completionGoals>
    </configuration>
</plugin>
  • release配置文件定义了Maven SCM插件的配置
  • maven Replacer插件使用replacerVersion参数在某些文件中设置正确的版本
  • clean是由Maven Release插件运行的标准目标(默认值:clean verify
  • replacer:replace目标负责修改文件
  • scm:checkin确实承诺并推动
  • verify是由Maven Release插件运行的标准目标(默认值:clean verify

接下来我配置了Maven Replacer plugin

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.3</version>
    <configuration>
        <includes>
            <include>${basedir}/file1.txt</include>
            <include>${basedir}/file2.txt</include>
        </includes>
        <replacements>
            <replacement>
                <token><![CDATA[<pattern>.*</pattern>]]></token>
                <value><![CDATA[<pattern>${replacerVersion}</pattern>]]></value>
            </replacement>
        </replacements>
    </configuration>
</plugin>

${replacerVersion}允许使用相同的配置从开发版更改为发行版,然后从发行版更改为下一个开发版。

最后我定义了我想使用哪个版本的Maven SCM plugin

<plugin>
    <artifactId>maven-scm-plugin</artifactId>
    <version>1.9.5</version>
</plugin>

并在release配置文件中配置它(我在配置文件中定义它以防止在非发布版本期间意外提交):

<profile>
    <id>release</id>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-scm-plugin</artifactId>
                    <configuration>
                        <message>[maven-scm-plugin] set ${replacerVersion} version in files</message>
                        <includes>file1.txt, file2.txt</includes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profile>

感谢执行命令后:

mvn release:prepare -DdevelopmentVersion=1.2.1-SNAPSHOT -DreleaseVersion=1.2.0 -Dtag=1.2.0

我看到4个提交:

  1. [maven-scm-plugin]在文件中设置1.2.0版本
  2. [maven-release-plugin]准备版本1.2.0
  3. [maven-scm-plugin]在文件中设置1.2.1-SNAPSHOT版本
  4. [maven-release-plugin]为下一次开发迭代做准备

0
投票

似乎未能允许指定其他标记文件实际上是Maven中的一个错误。在Maven Release Plugin的org.apache.maven.shared.release.phase.AbstractScmCommitPhase类的第130行,引用了Maven 2.0-beta-7中首次引入的“commitByProject”标志。

分支用于确定将文件添加到Maven版本的机制:prepare commit。 SCM插件使用SCMFileSet class在提交之前加载文件。该类的一个分支实例可能一直在尝试添加基本目录中的所有文件,但它在SCM中不起作用。

这是一个可以实现修复以获取文件列表或添加要提交的文件目录的点。

最后,在深入探讨Maven Release Plugin的调试执行之后,它正在调用SCM插件来仅添加来自repos的POM。更改记录不良的“commitByProject”标志对于将哪些文件添加到SCM提交中的结果没有任何影响。

© www.soinside.com 2019 - 2024. All rights reserved.