15

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

问题是在执行提交时,插件明确指定只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

我有什么方法可以覆盖此行为并指定要包含在提交中的其他文件或 glob?

(我也需要这种行为,completionGoals因为我已配置为进行相同的转换)

4

3 回答 3

9

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

首先我配置了Maven Release 插件来执行额外的目标:

<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>
  • releaseprofile 定义了 Maven SCM 插件的配置
  • replacerVersionMaven Replacer 插件使用参数在某些文件中设置正确的版本
  • clean是由 Maven Release 插件运行的标准目标(默认clean verify:)
  • replacer:replace目标负责修改文件
  • scm:checkin确实提交并推送
  • verify是由 Maven Release 插件运行的标准目标(默认clean verify:)

接下来我配置了 Maven Replacer 插件

<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>
    <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] 为下一次开发迭代做准备
于 2017-12-14T15:51:55.937 回答
8

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

于 2012-04-18T03:19:26.230 回答
0

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

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

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

最重要的是,在深入研究 Maven 发布插件的调试执行之后,它正在调用 SCM 插件以仅添加来自存储库的 POM。更改记录不充分的“commitByProject”标志对将哪些文件添加到 SCM 提交中的结果的影响为零。

于 2017-05-02T00:45:06.003 回答