user1246225
user1246225

Reputation: 31

Committing an additional file during Maven Release: What if we need to add it to version control first?

Is there a known way to commit changes to an additional file during the Maven Release, and also add that file to version control if it's necessary?

We have a resource file that is potentially changed during our build process, and we want to commit any changes to this file during the Maven Release so the most accurate version is reflected in our tags.

We can get most of the way by configuring maven-scm-plugin to checkin changes to our file, and adding scm:checkin to the preparationGoals of maven-release-plugin, like so:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-scm-plugin</artifactId>
    <version>1.9.5</version>
    <configuration>
      <includes>resource.file</includes>
      <message>[maven-scm-plugin] Committing resource.file from latest release</message>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
      <preparationGoals>clean verify scm:checkin</preparationGoals>
    </configuration>
  </plugin>

This approach handles new changes to an existing resource file just fine. Unfortunately, it fails when our build generates a new resource file that is not already added to version control:

[INFO] [ERROR] Provider message:
[INFO] [ERROR] The svn command failed.
[INFO] [ERROR] Command output:
[INFO] [ERROR] svn: E200009: Commit failed (details follow):
[INFO] svn: E200009: '/acme/builder/workspace/_experiment-commit-on-release/resource.file' is not under version control

While we can get around this case by adding scm:add to preparationGoals, that approach will break when our resource file is added to version control:

[INFO] [ERROR] Provider message:
[INFO] [ERROR] The svn command failed.
[INFO] [ERROR] Command output:
[INFO] [ERROR] svn: warning: W150002: '/acme/builder/workspace/_experiment-commit-on-release/resource.file' is already under version control
[INFO] svn: E200009: Could not add all targets because some targets are already versioned
[INFO] svn: E200009: Illegal target for the requested operation

I'm sure I can have Maven call some external script to handle this problem for us, but I'd rather keep this logic within Maven itself if at all possible.

Upvotes: 1

Views: 710

Answers (0)

Related Questions