3

I want to git commit two files in different folders with maven scm plugin (v1.9.4). Eg: abc/p.json and xyz\p.json. I dont want to commit any other files such as other/p.json

According to the documentation for the chekin goal, a comma separated list such as abc/p.json,xyz/p.json should work. But it ends up commiting all the files.

I am using the scm:checkin goal with the maven release plugin's <preparationGoals> configuration.

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

How do I commit just the abc/p.json and xyz/p.json files?

Aruna Herath
  • 6,241
  • 1
  • 40
  • 59
  • **Vote** for [this feature request](https://issues.apache.org/jira/browse/MRELEASE-798) – Vivek Apr 18 '21 at 09:04

1 Answers1

2

I was able to get a list of files checked in by creating a profile, similar to:

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

And then, in the release plugin configuration:

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

Reference: formatter-m2e-configurator's pom.xml

Christopher
  • 2,427
  • 19
  • 24
  • Thanks! Is there a way to oder the preparation goals? The files I want to commit are updated in the `verify` lifecycle. But with this config `scm:checkin` runs before `verify` runs :( – Aruna Herath Mar 07 '18 at 06:31
  • my config: `clean verify scm:add scm:checkin -Pcommit-version-updated-files` – Aruna Herath Mar 07 '18 at 06:32
  • It seems incorrect to me to have files modified in the `verify` phase, and I would look there to fix the problem. Everything that is modified should be done before the `package` phase. That said... you could probably put the execution itself in the profile, and select the phase in which you want it to be run, rather than trigger the goal from the command-line in ``. However, there aren't many phases after `verify`, and binding to `verify` itself might not guarantee it will run after the other plugin bound to `verify`. – Christopher Mar 07 '18 at 08:14
  • Ah. Sorry I was wrong. it is actually in the `validate` phase that we update version text. Not `verify`. But `scm:checkin` goal runs even before that. If the execution is bound to the profile I'll use `post-validate` phase. Then still the profile should be activated in `preparationGoals` and `completionGoals` right? Thanks a lot for your help :) – Aruna Herath Mar 07 '18 at 11:35
  • There is no `post-validate` phase in the build lifecyle (https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html). But, binding to `initialize` should work... just make sure you bind both `scm:add` and `scm:checkin` to that phase, and that you have `scm:add` execute first (you could bind `scm:checkin` to `generate-sources` if you really wanted to be sure). When you activate it depends on when changes occur. In my case, a plugin changed files during the `clean` phase for both `release:prepare` and `release:perform`, so I did both. Your situation may differ. – Christopher Mar 09 '18 at 00:11