SBT not passing credentials when publishing to Art

2019-07-15 13:12发布

问题:

I am coding a Java project and I'm automating the build and the publishing to JFrog Artifactory using SBT.

Whenever it's time to publish to Artifactory I want to do it using the Ivy directory layout and obviously publish the Ivy XML file along with the jar. I managed to achieve this by using the following lines in the build.sbt file:

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

However it only works when anonymous users are allowed to deploy into Artifactory. I realized that sbt is not really passing my credentials to Artifactory but, instead, logging in as anonymous.

My $HOME/.ivy2/.credentials file looks like this:

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

However, if I change the Artifactory configuration in order to prevent anonymous users from deploying new Artifacts, when I run "sbt publish" I get the following output:

[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

The Artifactory request.log file then contains:

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

I have also tried passing the credentials manually instead of using a file:

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

But I am getting the same result.

Any idea what I might be missing?

回答1:

try:

host=<Artifactory IP>

old answer (doesn't work):

host=<Artifactory IP>:<Artifactory port>


回答2:

I had a different problem: I had the wrong realm set on my .credentials file.

Looking at the error output from sbt, I was able to figure out that I should use:

realm=Artifactory Realm

Error shows the expected values for realm and host:

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