使用 Maven 外部化 SCM 凭证

发布于 2024-08-01 14:39:54 字数 89 浏览 4 评论 0 原文

有没有一种方法可以外部化我的 SCM 凭据,以便它们不会存储在项目的 POM 中? 问题是,如果它们包含在项目的 POM 中,那么在部署项目时它们将对所有人可见。

Is there a method to externalize my SCM credentials so they are not stored in the project's POM? The problem being if they're contained in the project's POM, they will be visible to all when the project is deployed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天邊彩虹 2024-08-08 14:39:54

我已经通过使用上面提供的解决方案成功实现了这一点,即将新的服务器配置添加到我的settings.xml 中并将域名作为id。

<server>
  <id>domain.name:port</id>
  <username>[username]</username>
  <password>[password]</password>
</server>

除了前面的答案之外,如果您在 URL 中指定端口,则还需要将其包含在 server.id 中。 我发现的另一个怪癖是,如果密码包含任何可能干扰命令行调用的字符,则需要将密码放在引号中。

您不能在 $user.home/.scm/svn-settings.xm 中使用以下内容,因为它无效! 下没有 等元素(如指定的 此处)

<svn-settings>
  <user>[svn user]</user>
  <password>[svn password]</password>
</svn-settings>

I've managed to get this to work by using the solution provided above i.e. adding a new server configuration to my settings.xml and giving the domain name as the id.

<server>
  <id>domain.name:port</id>
  <username>[username]</username>
  <password>[password]</password>
</server>

In addition to the previous answer, if you are specifying a port in your URL this also need to be included in the server.id. Another quirk that I found is that you need to put the password in quotes if it contains any characters that might interfere with the command line call.

You cannot use the following in your $user.home/.scm/svn-settings.xm as it is not valid! There are no such elements as <user> and <password> under <svn-settings> (as specified here )

<svn-settings>
  <user>[svn user]</user>
  <password>[svn password]</password>
</svn-settings>
痴者 2024-08-08 14:39:54

我意识到这个问题很旧,答案已被接受,但为了完整起见,我想提供以下替代方案,在某些情况下可能是首选。

动机

有时会发生相同的情况服务器有多种用途,需要不同的用户凭据。 例如,它用于托管 Nexus 驱动的 Maven 存储库以及同一用户具有不同凭据的 SVN 服务器。 在这种情况下,需要有多个 条目具有相同的 idusername,但 password< /代码>。 然而,这是不可行的。

解决方案

Maven 发布插件支持标志 usernamepassword,它们可以作为 release:preparerelease:perform 的一部分提供。代码>命令。 usernamepassword 的值应与相应的 SVN 凭据匹配。

mvn release:prepare -Dusername=[username] -Dpassword=[password] 

I realise that this question is old and the answers is accepted, but for the sake of completeness would like to provide the following alternative, which might be preferred in certain cases.

Motivation

It so sometimes happens that the same server is used for several purposes, which requires different user credentials. For example, it is used for hosting Nexus-driven Maven repository as well as an SVN server that have different credentials for the same user. In such cases, there would need to be several <server> entries with the same id and username, but different password. This, however, is not viable.

Solution

Maven release plugin supports flags username and password that can be provided as part of the release:prepare and release:perform commands. Values for username and password should match the respective SVN credentials.

mvn release:prepare -Dusername=[username] -Dpassword=[password] 
七色彩虹 2024-08-08 14:39:54

许多 SCM 提供商都可以这样做,我假设 Subversion 是基于您的标签的实现。

您可以在 $user.home/.scm/svn-settings.xml (或 [maven home]/conf/.scm/svn-settings.xml)中定义 Subversion 设置,但这意味着它们仍然对以下用户可见系统)

在该文件中,您可以设置 Subversion 服务器的用户名和密码。 文件内容应如下所示:

<svn-settings>
  <user>[svn user]</user>
  <password>[svn password]</password>
</svn-settings>

您可以在该配置文件中定义一些其他属性。 有关更多详细信息,请参阅 Subversion SCM 页面 的“提供程序配置”部分。

其他 SCM 提供商也有类似的方法,例如在 CVS 中,设置存储在同一位置(.scm 文件夹)的 cvs-settings.xml 中,请参阅 CVS SCM 页面 了解详细信息。

This can be done for many of the SCM providers, I assume Subversion as the implementation based on your tag.

You can define your Subversion settings in $user.home/.scm/svn-settings.xml (or [maven home]/conf/.scm/svn-settings.xml, though this means they'll still be visible to users of the system)

In that file you can set your username and password for the Subversion server. The file contents should look like this:

<svn-settings>
  <user>[svn user]</user>
  <password>[svn password]</password>
</svn-settings>

You can define some other properties in that configuration file. For more details see the "Provider Configuration" section of Subversion SCM page.

Other SCM providers have a similar approach, for example in CVS the settings are stored in cvs-settings.xml in the same location (the .scm folder), see the CVS SCM page for details.

撕心裂肺的伤痛 2024-08-08 14:39:54

对于某些 SCM 提供商,您可以在 settings.xml 部分中指定您的凭据。 使用存储库的域名作为 。 这对我来说对 Mercurial 有用。 SubVersion 也可以工作。

例如,假设我的 pom.xml 包含:

<scm>
  <connection>scm:hg:http://jukito.googlecode.com/hg/</connection>
  <developerConnection>scm:hg:https://jukito.googlecode.com/hg/</developerConnection>
  <url>http://code.google.com/p/jukito/source/browse/</url>
</scm>

那么我可以在 settings.xml 中指定我的凭据,如下所示:

<server>
  <id>jukito.googlecode.com</id>
  <username>philippe.beaudoin</username>
  <password>1234567890ABC</password>
</server>

For some SCM providers you can specify your credentials in the <servers> section of settings.xml. As an <id> use the domain name of your repository. This works for me with mercurial. SubVersion works too.

For example, given my pom.xml contains:

<scm>
  <connection>scm:hg:http://jukito.googlecode.com/hg/</connection>
  <developerConnection>scm:hg:https://jukito.googlecode.com/hg/</developerConnection>
  <url>http://code.google.com/p/jukito/source/browse/</url>
</scm>

Then I can specify my credentials in settings.xml as such:

<server>
  <id>jukito.googlecode.com</id>
  <username>philippe.beaudoin</username>
  <password>1234567890ABC</password>
</server>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文