如何使用标准 SSH 语法为 Maven Release 插件指定 Git 远程 URL?

uvs*_*tid 7 java git ssh maven

直接解决具体问题

如果我指定带有路径的“完全限定”SSH地址 pom.xml

<scm>
  <developerConnection>scm:git:username@hostname:/absolute/path/to/repo.git</developerConnection>
</scm>
Run Code Online (Sandbox Code Playgroud)

并在命令中使用它

mvn --batch-mode release:prepare -Dtag=whatever -DreleaseVersion=3.0 -DdevelopmentVersion=4.0-SNAPSHOT
Run Code Online (Sandbox Code Playgroud)

然后我得到错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project maven_dependencies: Unable to tag SCM
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] fatal: 'hostname/absolute/path/to/repo.git' does not appear to be a git repository
[ERROR] fatal: Could not read from remote repository.
Run Code Online (Sandbox Code Playgroud)

注意:hostname和之间的分号在错误输出/absolute/path/to/repo.git中pom.xml消失了!

额外细节

绝对路径 vs 相对路径

实际上,我可以在 SSH URL(相对于的主目录)中使用具有非绝对路径的Git usernname。例如,使用

scm:git:username@hostname:path/to/repo.git
Run Code Online (Sandbox Code Playgroud)

代替

scm:git:username@hostname:/home/username/path/to/repo.git
Run Code Online (Sandbox Code Playgroud)

完美地工作。

官方文档

我已经阅读了 Git 的官方 Maven Release 文档,并且因为标准的 SSH-like URL 至少在相对路径的情况下已经工作,我故意忽略了它奇怪的 URL 规范:

scm:git:ssh://username@hostname[:port]/~/path/to/repository
Run Code Online (Sandbox Code Playgroud)

反对和忽略此语法的原因是无法暗示相对于用户家的路径(如果路径不以 开头,SSH 默认会这样做/)。此外,标准 SSH 类 URL:后hostname的冒号是hostname和 路径(不是端口号)之间的分隔符!

这意味着 SSH 的 Git URL 必须专门为 Maven Release 插件重新格式化——真令人头疼!