scala 尝试从 Artifactory 虚拟存储库下载时,SBT 无法找到凭据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40224921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:46:49  来源:igfitidea点击:

SBT is unable to find credentials when attempting to download from an Artifactory virtual repo

scalasbtartifactory

提问by Salim Fadhley

I'm trying to run SBT behind a corporate firewall. Another team has configured an Artifactory proxy. This proxy works fine with anonymous access switched on, but when we make it require a password thinks start to go wrong.

我正在尝试在公司防火墙后面运行 SBT。另一个团队配置了一个 Artifactory 代理。这个代理在匿名访问打开的情况下工作正常,但是当我们让它需要密码时,就会开始出错。

When I run SBT on my workstation I get the following error:

当我在工作站上运行 SBT 时,出现以下错误:

[error] Unable to find credentials for [Artifactory Realm @ coderepo.xxx.amrs.bigco.com]

The result of this is that I cannot bootstrap sbt:

这样做的结果是我无法引导 sbt:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scala-lang#scala-library;2.10.6: not found
[warn]  :: org.scala-sbt#sbt;0.13.12: not found
[warn]  :: org.scala-lang#scala-compiler;2.10.6: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

I've tried putting a .credentials file in ~/.sbt and also ~/.ivy2: I have been testing variations on the following, all of which do not work:

我试过在 ~/.sbt 和 ~/.ivy2 中放置一个 .credentials 文件:我一直在测试以下变体,所有这些都不起作用:

realm=Artifactory Realm @ coderepo.xxx.amrs.bigco.com
host=coderepo.xxx.amrs.bigco.com
user=<username>
password=<pwd>

I'm guessing that this error means that it was unable to locate a credentials definition that matched the realm, so I tried a number of versions of the first line in both locations:

我猜这个错误意味着它无法找到与领域匹配的凭据定义,所以我在两个位置尝试了第一行的多个版本:

realm=Artifactory Realm
realm=[Artifactory Realm @ coderepo.xxx.amrs.bigco.com]
realm=coderepo.xxx.amrs.bigco.com

None of which seem to have any impact at all.

这些似乎都没有任何影响。

So what is the correct way to allow SBT to authenticate with username & password to a password protected Artifactory repository?

那么,允许 SBT 使用用户名和密码对受密码保护的 Artifactory 存储库进行身份验证的正确方法是什么?

UPDATE0: According to the Ivy documentation, the most likely realm name is simply "Artifactory Realm". According to the SBT documentation, the correct default location of the credentials file should be %USERPROFILE%/.sbt/.credentials (yes, I'm using Windows). Even after deleting the .credentials file in my .ivy2 directory it still doesn't work.

UPDATE0:根据常春藤文档,最有可能的领域名称就是“Artifactory Realm”。根据 SBT 文档,凭据文件的正确默认位置应该是 %USERPROFILE%/.sbt/.credentials(是的,我使用的是 Windows)。即使删除了我的 .ivy2 目录中的 .credentials 文件,它仍然不起作用。

UPDATE1: Relevant but not actually helpful:

UPDATE1:相关但实际上没有帮助:

UPDATE2: I'm starting to suspect that this is a bug in sbt - I've added an issue here: https://github.com/sbt/sbt/issues/2817

UPDATE2:我开始怀疑这是 sbt 中的错误 - 我在这里添加了一个问题:https: //github.com/sbt/sbt/issues/2817

回答by Olli Helenius

See this questionfor details on how to configure global credentials.

有关如何配置全局凭据的详细信息,请参阅此问题

To summarise:

总结一下:

If you need to boot SBT from a proxy repository, set the system property sbt.boot.credentialsto point to your credentials file. You can do this in your %CSIDL_PROGRAM_FILESX86%/sbt/conf/sbtconfig.txt, for example:

如果您需要从代理存储库启动 SBT,请将系统属性设置sbt.boot.credentials为指向您的凭据文件。您可以在您的 中执行此操作%CSIDL_PROGRAM_FILESX86%/sbt/conf/sbtconfig.txt,例如:

-Dsbt.boot.credentials=/Users/my-user-name/.sbt/credentials

Alternatively you can use the SBT_CREDENTIALSenvironment variable for the same purpose.

或者,您可以将SBT_CREDENTIALS环境变量用于相同目的。

For Artifactory, the realm in the credentialsfile should be set to:

对于 Artifactory,credentials文件中的领域应设置为:

realm=Artifactory Realm

For authenticating dependency artifact retrieval, create a file like %USERPROFILE%/.sbt/0.13/plugins/my-credentials.sbtwith a credentialssetting. For example:

为了验证依赖构件的检索,创建一个文件像%USERPROFILE%/.sbt/0.13/plugins/my-credentials.sbt一个credentials设置。例如:

credentials += Credentials(Path.userHome / ".sbt" / "credentials")

回答by Darren Bishop

I think the default location for this file is ${HOME}/.sbt/<sbt-version>/.credentials; while I trust there is published documentation on this, I confirmed this by clicking around in the code.
@salim-fadhley, looks like you are missing the SBT version in the path.

我认为这个文件的默认位置是${HOME}/.sbt/<sbt-version>/.credentials; 虽然我相信有关于此的已发布文档,但我通过在代码中单击来确认这一点。
@salim-fadhley,看起来您在路径中缺少 SBT 版本。

EDIT:You need to add DefaultOptions.addCredentialsto your build.sbt; you can then verify what SBT picks up with show credentials.

编辑:您需要添加DefaultOptions.addCredentials到您的 build.sbt; 然后,您可以验证 SBT 使用show credentials.

File location aside, there seems to be confusion between repository names (mean nothing) vs. security realms (mean everything).

除了文件位置之外,存储库名称(毫无意义)与安全领域(意味着一切)之间似乎存在混淆。

The auth-challenge that comes back from the repository server will include the name of the security realm; as a client/developer, you have no control over what it is and my guess is it must match the realmyou (client/developer) specify in your .credentialsfile (wherever that is).

从存储库服务器返回的 auth-challenge 将包括安全领域的名称;作为客户/开发人员,您无法控制它是什么,我猜它必须与您(客户/开发人员)在文件中指定的领域.credentials(无论在哪里)相匹配。

Meanwhile, the repository name (as featured in build.sbt) actually means nothing to anyone outside development of the corresponding project e.g. the repository server admins could not care from one project to the next.

同时,存储库名称(如 中所示build.sbt)实际上对相应项目开发之外的任何人都没有任何意义,例如,存储库服务器管理员不会关心从一个项目到下一个项目。