如何使用SBT访问受保护的Nexus? [英] How to access a secured Nexus with sbt?

查看:141
本文介绍了如何使用SBT访问受保护的Nexus?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问Nexus存储库管理器,该管理器需要一些基本身份验证. Maven2一切正常,但是当我尝试在SBT中进行配置时,找不到工件.它使用的是自定义存储库模式(请参阅此相关问题),但我认为这无关紧要.无论如何,相关的配置都在这里.

I'm trying to access a Nexus repository manager which requires some basic authentication. Everything works fine from Maven2 but when I try to configure things in SBT it can't find the artifacts. It is using a custom repository pattern (see this related question) but I don't think that should matter. In any case the relevant configuration is here.

Project.scala:

Project.scala:

val snapshotsName = "Repository Snapshots"
val snapshotsUrl = new java.net.URL("http://nexusHostIp:8081/nexus/content/repositories/snapshots")
val snapshotsPattern = "[organisation]/[module]/[revision]-SNAPSHOT/[artifact]-[revision](-[timestamp]).[ext]"
val snapshots = Resolver.url(snapshotsName, snapshotsUrl)(Patterns(snapshotsPattern))
Credentials(Path.userHome / ".ivy2" / ".credentials", log)

val dep = "group" % "artifact" % "0.0.1" extra("timestamp" -> "20101202.195418-3")

〜/.ivy2/.凭据:

~/.ivy2/.credentials:

realm=Snapshots Nexus
host=nexusHostIp:8081
user=nexususername
password=nexuspassword

根据 SBT用户组中的类似讨论应该可以正常工作,但是在尝试构建时会得到以下提示.

According to a similar discussion in the SBT user group this should work fine but I am getting the following when I try to build.

==== Repository Snapshots: tried
[warn]    -- artifact group#artifact;0.0.1!artifact.jar:
[warn]    http://nexusHostIp:8081/nexus/content/repositories/snapshots/group/artifact/0.0.1-SNAPSHOT/artifact-0.0.1-20101202.195418-3.jar

我相当确定这是一个凭证问题,而不是其他问题,因为我可以点击它说它正在直接尝试并下载jar(经过身份验证)的URL.

I'm fairly certain this is a credentials problem and not something else because I can hit the URL it says it is trying directly and download the jar (after authenticating).

我也尝试过内联声明凭据(即使它不理想),如下所示:

I have also tried declaring the credentials inline (even though it is less than ideal) like so:

Credentials.add("Repository Snapshots", "nexusHostIp", "nexususername", "nexuspassword")

推荐答案

这就是我所做的(sbt 0.13 +人工制品-连结的设置应该类似):

Here's what I did (sbt 0.13 + artifactory - setup should be similar for nexus):

1)按照此处指定的方式编辑文件〜/.sbt/repositories:

1) Edited the file ~/.sbt/repositories as specified here: http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Proxy-Repositories.html

[repositories]
  local
  my-ivy-proxy-releases: http://repo.company.com/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  my-maven-proxy-releases: http://repo.company.com/maven-releases/

2)锁定我的工件以禁用匿名访问.

2) Locked down my artifactory to disable anonymous access.

3)在〜/.sbt/.credentials中创建凭证文件

3) Created a credentials file in ~/.sbt/.credentials

realm=Artifactory Realm
host=artifactory.mycompany.com
user=username
password=password

4)在〜/.sbt/0.13/plugins/credentials.sbt下创建一个文件,用于连接默认凭据

4) Created a file under ~/.sbt/0.13/plugins/credentials.sbt that wires up the default credentials

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

现在,当我的项目加载sbt时,击中的伪像会像通常的那样.

Now when my project loads sbt hits artifactory like normal.

我这样做的原因是将存储库定义等保留在项目文件之外,以使团队具有灵活性(他们可以设置内部服务器来处理进行中的工件等).

The reason I did it this way is to keep the repository definitions, etc, out of the project files to enable teams to have flexibility (they can set up an internal server to serve in-progress artifacts, etc).

-奥斯丁

这篇关于如何使用SBT访问受保护的Nexus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆