To prepare your build in SBT basically do these things. Add values for the publishTo Setting and the credentials Task. I recommend using a credentials file not under version control for obvious reasons. The first thing you want to verify is that you are using the correct “realm” value, which can be either a property in the credentials file or the first argument to the constructor of the Credentials class. Use curl to figure out the correct value as explained here. Send a POST to the Nexus repository which you want to publish to without any authentication arguments. For us this was the call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST http://10.20.108.220:8081/nexus/content/repositories/releases -v |
Look for the WWW-Authenticate header and use the realm value. I think the default is “Sonatype Nexus Repository Manager”.
This was a step in the right direction but we still got the following error in SBT:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[trace] Stack trace suppressed: run last *:publish for the full output. | |
[error] (*:publish) java.io.IOException: Access to URL http://10.20.108.220:8081/nexus/content/repositories/releases/se/foo/operations/nexustest_2.10/0.1/nexustest_2.10-0.1.pom was refused by the server: Unauthorized |
Not super useful but more info is actually available in the Nexus logfiles. Make sure you set the loglevel to DEBUG via the Nexus admin GUI first, then tail nexus.log while you try to publish from SBT. Here is some output in nexus.log, basically saying that SBT did not sent a value for username and password as part of the Basic Authentication.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2014-02-12 13:03:53 DEBUG DefaultSessionManager - Unable to resolve session ID from SessionKey. Returning null to indicate a session could not be found. | |
2014-02-12 13:03:53 DEBUG NexusContentAuthenticationFilter - No authorization found (header or request parameter) | |
2014-02-12 13:03:53 DEBUG NexusContentAuthenticationFilter - No authorization found (header or request parameter) | |
2014-02-12 13:03:53 DEBUG NexusContentAuthenticationFilter - Attempting to authenticate Subject as Anonymous request... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// next line contains the error | |
credentials += Credentials("Sonatype Nexus Repository Manager", "10.20.108.220:8081", "username", "password") | |
publishTo := { | |
val nexus = "http://10.20.108.220:8081/nexus/" | |
if (version.value.trim.endsWith("SNAPSHOT")) | |
Some("snapshots" at nexus + "content/repositories/snapshots") | |
else | |
Some("releases" at nexus + "content/repositories/releases") | |
} |
After running a few tests, I figured out that the second argument to the sbt.Credentials class should only be the host and must not include the port – doh! After fixing this, everything works just fine. Another thing you want to check via the Nexus admin GUI is the Access Settings of your repository. For “Deployment Policy” we have set it to “Allow Redeploy”.
1 Kommentare:
Thank you very much man! That was really helpful: concise and to the point. Please do not delete the post as I will keep it for the future records...Thanks again!
Kommentar veröffentlichen