SBT在发布到Artifactory时未传递凭据

时间:2016-02-19 04:00:06

标签: sbt artifactory

我正在编写一个Java项目,我正在使用SBT自动构建和发布到JFrog Artifactory。

每当有时间发布到Artifactory时,我想使用常春藤目录布局来做,并且显然会发布Ivy XML文件和jar。我设法通过在build.sbt文件中使用以下行来实现此目的:

crossPaths := false
publishTo := Some("Artifactory Realm" at "http://<Artifactory IP>:<Artifactory Port>/artifactory/org.project.my")
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
publishMavenStyle := false

但是,只有在允许匿名用户部署到Artifactory时才能使用它。我意识到sbt并没有真正将我的凭据传递给Artifactory,而是以匿名方式登录。

我的$HOME/.ivy2/.credentials文件如下所示:

realm=Artifactory Realm
host=http://<Artifactory IP>:<Artifactory Port>/artifactory/org.project.my
user=<my user name>
password=<my user name>

但是,如果我更改Artifactory配置以防止匿名用户部署新工件,那么当我运行&#34; sbt publish&#34;我得到以下输出:

[error] Unable to find credentials for [Artifactory Realm @ <Artifactory IP>].
java.io.IOException: Access to URL http://<Artifactory IP>:<Artifactory Port>/artifactory//org.project.my/org/project/my/project-my/1.0.0/project-my-1.0.0.jar was refused by the server: Unauthorized

Artifactory request.log文件随后包含:

20160219011657|319|REQUEST|10.0.2.2|anonymous|PUT|/org.project.my/org/project/my/project-my/1.0.0/project-my-1.0.0.jar|HTTP/1.1|401|24978

我还尝试手动传递凭据而不是使用文件:

credentials += Credentials("Artifactory Realm", "localhost", "<USERNAME>", "<PASS>")

但我得到的结果相同。

知道我可能缺少什么吗?

2 个答案:

答案 0 :(得分:4)

尝试:

 
host=<Artifactory IP>

旧答案(不起作用):

 
host=<Artifactory IP>:<Artifactory port>

答案 1 :(得分:3)

我遇到了另一个问题:我的realm文件设置错误.credentials

查看sbt的错误输出,我能够确定我应该使用:

realm=Artifactory Realm

错误显示realmhost的预期值:

[error] Unable to find credentials for [Artifactory Realm @ myhost].