'How to make the maven release plugin work on widows with SSH outside of git-bash?
I have a mvn release command that works on Windows inside a git-bash but as soon as I try in a cmd window, it fails.
The command is :
mvn -X -B -Dusername=git release:clean release:prepare release:perform
The error is the following :
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] [email protected]: Permission denied (publickey).
[ERROR] fatal: Could not read from remote repository.
My maven settings file is located as the default path ~/.m2/settings.xml and looks like:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<servers>
<server>
<id>github.com</id>
<username>git</username>
<privateKey>C:\Users\nicol\.ssh\id_ed25519</privateKey>
<!-- also tried with ${user.home}/.ssh/id_ed25519 -->
<passphrase>nico</passphrase>
</server>
</servers>
</settings>
I generated a private key using the command from the Github guide on deploy keys :
ssh-keygen -t ed25519 -C "[email protected]"
I uploaded the public key on the "Deploy keys" section of the Github repo.
Here's how the pom.xml looks like :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.myusername</groupId>
<artifactId>myrepo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.scm.id>github.com</project.scm.id>
</properties>
<scm>
<connection>scm:git:https://github.com/myusername/myrepo.git</connection>
<developerConnection>scm:git:ssh://[email protected]/myusername/myrepo.git</developerConnection>
<url>https://github.com/myusername/myrepo</url>
<tag>HEAD</tag>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<arguments>${arguments}</arguments>
<goals>install</goals>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
</project>
Below the version details :
- git version 2.34.1.windows.1
- java version "17.0.1" 2021-10-19 LTS
- Apache Maven 3.8.4
I tested with and without ssh agent on git-bash : it worked.
With cmd, I keep getting the same error.
What's going on ? How will I make it work on cmd ?
A bit of context: What I'm trying to build fails on ubuntu linux due to some tricky library issue and as it builds a Windows executable, it would probably make more sense to build on Windows. I plan to put the whole process into a Github workflow so I'd like it to validate it locally first. If the Github workflow/actions has an embedded Git-Bash, that could help too.
*** EDIT after @khmarbaise's comment ***
As I saw a mess in known_hosts file, here's what I did:
- deleted entries of known_hosts file
- generated public/private keys with command above
- uploaded public key in the "Deploy keys" section of the repo
Then, in a cmd prompt, the following scenario worked fine for me:
- git clone ssh://[email protected]/myusername/myrepo.git
- cd myrepo
- echo. >> README.md
- git add README.md
- git commit -a -m "added space at the end of the README"
- git push
Then I tried again the maven release command:
mvn -X -B -Dusername=git release:clean release:prepare release:perform
And had the error again:
The git-push command failed.
Command output:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
