scalasbtarchiva

Publishing to Apache Archiva refused by the server with Unauthorized in SBT?


I have a multi-module SBT project that I am trying to publish to a remote Apache Archiva.

[error] (core/*:publish) java.io.IOException: Access to URL http://XX.XX.XX.XX/repository/development/com/example/core_2.10/1.0.0.SNAPSHOT.304fcd73d72ffe4a05271197902c36b9a59b4922/core_2.10-1.0.0.SNAPSHOT.304fcd73d72ffe4a05271197902c36b9a59b4922.pom was refused by the server: Unauthorized

For my snapshots, I'm appending the Git SHA-1 hash for the commit.

Build.scala

publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ => true },
publishTo := Some("development" at "http://XX.XX.XX.X/repository/development"),
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials_development"), // archiva credentials by repo

I took care to set the realm correctly per posts I've read. I retrieved it by doing:

curl -X POST http://xx.xx.xx.xx/repository/development -v > /dev/null

.credentials_development

realm=Repository Archiva Managed development Repository
host=XX.XX.XX.XX
user=myuser
password=mypassword

In SBT, I run:

compile
assembly
make-pom
package
publish

I can upload artifacts using the user via the web administration.

How should I be doing it so the publishing works? Do I perhaps need to setup credentials via ivysettings.xml?


Solution

  • A comment in this question led me to the answer: sbt: publish to corporate Nexus repository unauthorized

    One cannot include the port (my Archiva server is running on port 8080) on the hostname in the credentials file. It will prevent your credentials from being used during the publish.

    I also specified the realm in my publishTo and moved my credential file to ~/.sbt per barnesjd's comment (though not in plugins, just in ~./sbt).

    For reference to others, here is my configuration:

    Build.scala

    publishTo := Some("Repository Archiva Managed development Repository" at "http://XX.XX.XX.XX:8080/respository/development/"),
    credentials += Credentials(Path.userHome / ".sbt" / ".archiva_credentials")
    

    .archiva_credentials

    realm=Repository Archiva Managed development Repository
    host=XX.XX.XX.XX
    user=myuser
    password=mypassword