1

有没有一种已知的方法可以在 Maven 发布期间提交对附加文件的更改,并在必要时将该文件添加到版本控制中?

我们有一个在构建过程中可能会更改的资源文件,我们希望在 Maven 发布期间提交对该文件的任何更改,以便最准确的版本反映在我们的标签中。

我们可以通过配置 maven-scm-plugin 来检查对我们文件的更改,并添加scm:checkinpreparationGoalsmaven-release-plugin 中来获得大部分方法,如下所示:

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

这种方法可以很好地处理对现有资源文件的新更改。不幸的是,当我们的构建生成一个尚未添加到版本控制的新资源文件时,它会失败:

[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

虽然我们可以通过添加scm:addto 来解决这种情况,但是当我们的资源文件添加到版本控制时preparationGoals这种方法会中断:

[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

我确信我可以让 Maven 调用一些外部脚本来为我们处理这个问题,但如果可能的话,我宁愿将这个逻辑保留在 Maven 本身中。

4

0 回答 0