【问题标题】:Commit multiple files with maven scm plugin使用 maven scm 插件提交多个文件
【发布时间】:2018-02-23 11:59:45
【问题描述】:

我想用 maven scm 插件 (v1.9.4) 在不同的文件夹中 git commit 两个文件。例如:abc/p.jsonxyz\p.json。我不想提交任何其他文件,例如other/p.json

根据chekin 目标的documentationabc/p.json,xyz/p.json 等逗号分隔列表应该可以工作。但它最终会提交所有文件。

我将 scm:checkin 目标与 maven 发布插件的 <preparationGoals> 配置一起使用。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>${maven.release.plugin.version}</version>
    <configuration>
        <preparationGoals>
            clean verify
            scm:checkin -DpushChanges=false -Dmessage="[maven-release-plugin] Update version text"
            -Dincludes="abc/p.json,xyz/p.json"
    </configuration>
</plugin>

如何只提交 abc/p.jsonxyz/p.json 文件?

【问题讨论】:

标签: maven maven-scm


【解决方案1】:

我能够通过创建配置文件来获取签入的文件列表,类似于:

<profile>
  <id>commit-changed-files</id>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-scm-plugin</artifactId>
          <configuration>
            <includes>file1,file2,file3,file4</includes>
            <message>[maven-release-plugin] commit changed files</message>
            <pushChanges>false</pushChanges><!-- because I use git -->
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</profile>

然后,在发布插件配置中:

        <preparationGoals>-Pcommit-changed-files clean scm:add scm:checkin</preparationGoals>
        <completionGoals>-Pcommit-changed-files clean scm:add scm:checkin</completionGoals>

参考:formatter-m2e-configurator's pom.xml

【讨论】:

  • 谢谢!有没有办法对准备目标进行排序?我要提交的文件在verify 生命周期中更新。但是使用此配置 scm:checkinverify 运行之前运行 :(
  • 我的配置:&lt;preparationGoals&gt;clean verify scm:add scm:checkin -Pcommit-version-updated-files&lt;/preparationGoals&gt;
  • verify 阶段修改文件对我来说似乎是不正确的,我会在那里解决问题。修改的所有内容都应在package 阶段之前完成。也就是说......您可能会将执行本身放在配置文件中,并选择您希望它运行的阶段,而不是从&lt;preparationGoals /&gt; 中的命令行触发目标。但是,verify 之后的阶段并不多,绑定到verify 本身可能并不能保证它会在绑定到verify 的其他插件之后运行。
  • 啊。对不起我错了。实际上,我们更新版本文本是在validate 阶段。不是verify。但是scm:checkin 目标甚至在此之前就已经运行了。如果执行绑定到配置文件,我将使用post-validate 阶段。那么配置文件仍然应该在preparationGoalscompletionGoals 中激活,对吗?非常感谢您的帮助:)
  • 构建生命周期中没有 post-validate 阶段 (maven.apache.org/guides/introduction/…)。但是,绑定到initialize 应该可以工作......只要确保将scm:addscm:checkin 都绑定到该阶段,并且您首先执行scm:add(如果您可以将scm:checkin 绑定到generate-sources你真的很想确定)。何时激活取决于更改发生的时间。在我的例子中,一个插件在clean 阶段更改了release:preparerelease:perform 的文件,所以我两个都做了。您的情况可能会有所不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多