mvn release:prepare not committing changes to pom.

2020-01-26 04:37发布

I'm trying to release a Jenkins plugin (stashNotifier) with Maven and face a problem with the release plugin.

mvn clean release:prepare

runs to completion without errors but fails to commit the changed pom.xml in my local git repository. Even though it does tag the HEAD of the branch on which I'm trying to release version 1.0.2. This is what my local branch looks like before preparing the release

* df60768 (HEAD, origin/develop, develop) upgraded parent pom to version 1.498
* 792766a added distribution management section to pom.xml and amended readme.md 

and this is what it looks like after

* df60768 (HEAD, tag: stashNotifier-1.0.2, origin/develop, develop) upgraded parent pom to version 1.498
* 792766a added distribution management section to pom.xml and amended readme.md 

Unfortunately, the pom.xml already contains the next development version, which in turn causes a subsequent release:perform to release that snapshot version.

From the command output of maven, it almost looks like it's omitting the git commit command:

[INFO] Checking in modified POMs...
[INFO] Executing: /bin/sh -c cd /Users/gruetter/Dropbox/stashNotifier && git add -- pom.xml
[INFO] Working directory: /Users/gruetter/Dropbox/stashNotifier
[INFO] Executing: /bin/sh -c cd /Users/gruetter/Dropbox/stashNotifier && git status
[INFO] Working directory: /Users/gruetter/Dropbox/stashNotifier
[INFO] Tagging release with the label stashNotifier-1.0.2...
[INFO] Executing: /bin/sh -c cd /Users/gruetter/Dropbox/stashNotifier && git tag -F /var/folders/dr/xxbtyycs1z9dl2_snlj87zrh0000gn/T/maven-scm-678409272.commit stashNotifier-1.0.2
[INFO] Working directory: /Users/gruetter/Dropbox/stashNotifier
[INFO] Executing: /bin/sh -c cd /Users/gruetter/Dropbox/stashNotifier && git push git@github.com:jenkinsci/stashnotifier-plugin.git stashNotifier-1.0.2
[INFO] Working directory: /Users/gruetter/Dropbox/stashNotifier
[INFO] Executing: /bin/sh -c cd /Users/gruetter/Dropbox/stashNotifier && git ls-files
[INFO] Working directory: /Users/gruetter/Dropbox/stashNotifier
[INFO] Transforming 'Stash Notifier'...
[INFO] Not removing release POMs
[INFO] Checking in modified POMs...
[INFO] Executing: /bin/sh -c cd /Users/gruetter/Dropbox/stashNotifier && git add -- pom.xml
[INFO] Working directory: /Users/gruetter/Dropbox/stashNotifier
[INFO] Executing: /bin/sh -c cd /Users/gruetter/Dropbox/stashNotifier && git status
[INFO] Working directory: /Users/gruetter/Dropbox/stashNotifier
[INFO] Release preparation complete.

I'm running maven 3.0.5 (without --dry-run or -DpushChanges=false). Here are the relevant (I think) parts of my effective pom:

[...]

<scm>
   <connection>scm:git:git://github.com/jenkinsci/stashnotifier-plugin.git</connection>
   <developerConnection>scm:git:git@github.com:jenkinsci/stashnotifier-plugin.git</developerConnection>
   <url>https://github.com/jenkinsci/stashnotifier-plugin</url>
</scm>

[...]

<distributionManagement>
   <repository>
      <id>maven.jenkins-ci.org</id>
      <url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
   </repository>
   <snapshotRepository>
      <id>maven.jenkins-ci.org</id>
      <url>http://maven.jenkins-ci.org:8081/content/repositories/snapshots</url>
   </snapshotRepository>
   <site>
     <id>github-pages</id>
     <url>gitsite:git@github.com/jenkinsci/maven-site.git:plugin-parent/stashNotifier</url>
   </site>
</distributionManagement>

[...]

<properties>
   [...]
   <maven-release-plugin.version>2.2.2</maven-release-plugin.version>
   [...]
</properties>

[...]

<build>
   [...]
   <pluginManagement>
      <plugins>
         [...]
         <plugin>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.2.2</version>
         </plugin>
         [...]
   </pluginManagement>

   [...]

   <plugins>
      [...]
      <plugin>
         <artifactId>maven-release-plugin</artifactId>
         <version>2.2.2</version>
         <configuration>
            <goals>deploy</goals>
         </configuration>
      </plugin>
      [...]
   </plugins>
</build>

What am I doing wrong? Thanks in advance for your insights!

9条回答
兄弟一词,经得起流年.
2楼-- · 2020-01-26 04:42

Firstly, the answers from richnou and vasekt solved my problem I thought I'd post this answer just because of newer versions than have been mentioned and I thought it would be good to give an extra example including them.

I was running maven release plugin 2.3.2 with Git 3.3.x without specifying the maven scm dependency version, which was causing the snapshot issue. For me I just upgraded to the latest version at the time for both maven release plugin and the scm dependency which were as follows:

<plugin>
   <artifactId>maven-release-plugin</artifactId>
   <version>2.5.3</version>
   <dependencies>
      <dependency>
         <groupId>org.apache.maven.scm</groupId>
         <artifactId>maven-scm-provider-gitexe</artifactId>
         <version>1.9.5</version>
      </dependency>
   </dependencies>
</plugin>

This worked fine for me, release versions uploaded properly to the release repo and the snapshot worked as expected as well.

查看更多
虎瘦雄心在
3楼-- · 2020-01-26 04:45

Upgrading the maven-release-plugin to 2.5.2 helped (upgrading to 2.5 didn’t; it works for some people but not all, possibly depending on other newer software on the system). I believe it automatically pulls in the new provider.

查看更多
【Aperson】
4楼-- · 2020-01-26 04:54

I ran into the same problem, solution by #richnou works for me (upgrading SCM dependency). There is the issue created on this problem, see link below. The problem relates with new version of Git where "git status" returns localized messages which plugin cannot parse. It is the root cause. The issue was fixed in git scm (1.8.1 version) by using --porcelain option of git (which should return easily parsable output), but after this fix, another problem has raised - if repository root (scm tag) is not the working directory, release:prepare still fails. This issue seems to be fixed in snapshot version of Git SCM (not released yet). This can be workarounded by copiing scm tag into child pom.

MRELEASE-812

SCM-709

maven-release-plugin-and-git-fix

查看更多
三岁会撩人
5楼-- · 2020-01-26 04:54

I encountered this same problem when using cygwin+maven+git. It showed no errors but did not attempt to commit the pom changes, just stopped after git status:

[INFO] Checking in modified POMs...
[INFO] Executing: cmd.exe /X /C "git add -- pom.xml"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Tagging release with the label portal-automation-0.3.9...
[INFO] Executing: cmd.exe /X /C "git tag -F C:\cygwin64\tmp\maven-scm-1212196933.commit portal-automation-0.3.9"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git push git@barrel.mitre.org:org-mitre-caasd/portal-automation.git portal-automation-0.3.9"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git ls-files"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Transforming 'portal-automation'...
[INFO] Not removing release POMs
[INFO] Checking in modified POMs...
[INFO] Executing: cmd.exe /X /C "git add -- pom.xml"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Release preparation complete.

As you can see, no errors, just didn't commit after checking status. However when I ran from windows command prompt instead:

...
[INFO] Executing: cmd.exe /X /C "git add -- pom.xml"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git commit --verbose -F C:\Users\ltheisen\AppData\Local\Temp\maven-scm-2030091036.commit pom.xml"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git symbolic-ref HEAD"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Executing: cmd.exe /X /C "git push git@barrel.mitre.org:org-mitre-caasd/portal-automation.git master:master"
[INFO] Working directory: C:\Users\ltheisen\git\caasd-portal-automation
[INFO] Release preparation complete.

You can see that it did commit after checking the status. Not sure if this is your issue as well, but it worked for me.

Note that this would mean you need to install msysgit

查看更多
▲ chillily
6楼-- · 2020-01-26 04:57

I solved the issue on my side (running maven 3.0.5) by updating the git scm provider dependency, not the release plugin version:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-release-plugin</artifactId>
      <version>2.4.2</version>
      <dependencies>
        <dependency>
          <groupId>org.apache.maven.scm</groupId>
          <artifactId>maven-scm-provider-gitexe</artifactId>
          <version>1.8.1</version>
        </dependency>
       </dependencies>
      </plugin>
    </plugins>
</build>

The git scm 1.8.1 version correctly makes the git commit (tested with the prepare and rollback goals).

EDIT: Different versions of maven-release-plugin and maven-scm-provider-gitexe may be required depending on your environment. See the comments for more discussion.

查看更多
劳资没心,怎么记你
7楼-- · 2020-01-26 04:59

You are probably reading this because the above solutions have not worked for you. I had the same issue and I tried everything mentioned here. My versions were: maven-release-plugin 2.5 and git 1.7.9

The solution that worked for me was downgrading maven-release-plugin to version 2.3.2

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <autoVersionSubmodules>true</autoVersionSubmodules>
            </configuration>
        </plugin>
    </plugins>
</build>
查看更多
登录 后发表回答