scala sbt:发布到未经授权的企业 Nexus 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16425639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sbt: publish to corporate Nexus repository unauthorized
提问by fracca
Quick resolution
快速解决
The required credential expects the exact realm as defined by nexus. See below how to find the one you have defined, but most certainly is "Sonatype Nexus Repository Manager". Add the rest of the details to the credentials as normal.
所需的凭据需要由 nexus 定义的确切领域。请参阅下面如何找到您定义的那个,但最肯定的是“Sonatype Nexus Repository Manager”。像往常一样将其余详细信息添加到凭据中。
c:/data/user/.sbt/.credentials
c:/data/user/.sbt/.credentials
realm=Sonatype Nexus Repository Manager
host=nexus
user=repouser
password=password
build.sbt credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
build.sbt 凭证 += 凭证(Path.userHome / ".sbt" / ".credentials")
publishTo <<= version { v: String =>
val nexus = "http://nexus/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/libs-snapshots")
else
Some("releases" at nexus + "content/repositories/libs-releases")
}
Problem
问题
I'm trying to publish a jar into a corporate nexus repo.
我正在尝试将一个 jar 发布到一个企业关系存储库中。
I'm able to do this fine from Maven, and I have configured the repositories to be able to use Nexus to provide internal jars. However, publication fails due to authorization.
我可以从 Maven 中很好地做到这一点,并且我已经将存储库配置为能够使用 Nexus 来提供内部 jar。但是,由于授权,发布失败。
> publish
[info] Packaging c:\app\target\scala-2.10\app_2.10-0.1-sources.jar ...
[info] Wrote D:\app\target\scala-2.10\app_2.10-0.1.pom
[info] :: delivering :: com.app#app_2.10;0.1 :: 0.1 :: release :: Tue May 07 18:28:44 BST 2013
[info] Done packaging.
[info] delivering ivy file to D:\app\target\scala-2.10\ivy-0.1.xml
[info] Packaging D:\app\target\scala-2.10\app_2.10-0.1.jar ...
[info] Done packaging.
[trace] Stack trace suppressed: run last *:publish for the full output.
[error] (*:publish) java.io.IOException: Access to URL http://nexus/content/groups/common/com/app/app_2.10/0.1/app_2.10-0.1.pom was refused by the server: Unauthorized
c:/data/user/.sbt/.credentials
c:/data/user/.sbt/.credentials
realm=X
host=nexus
user=repouser
password=password
c:/data/user/.sbt/repositories
c:/data/user/.sbt/repositories
[repositories]
local
x-repo: http://nexus/content/groups/common
typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
sbt-plugin-releases: http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/
maven-central
app/build.sbt
应用程序/build.sbt
name := "app"
organization := "com.app"
version := "0.1"
scalaVersion := "2.10.1"
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.10" % "2.0.M5b" % "test"
)
EclipseKeys.withSource := true
publishMavenStyle := true
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
publishTo := Some("X Maven Repo" at "http://nexus/content/groups/common")
My Maven settings.xml
我的 Maven settings.xml
<mirrors>
<mirror>
<id>x-repo</id>
<name>X Maven repo</name>
<url>http://nexus/content/groups/common</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<servers>
<server>
<id>x-repo</id>
<username>repouser</username>
<password>password</password>
</server>
</servers>
I have followed instructions from official docand various other posts, including StackOverflow such this oneor mailing list such as this. None worked. I have tried enabling extra logging, but no further details are given.
我按照指示,从官方文档等各个岗位,包括StackOverflow的这等一个或邮件列表,如这个。没有一个工作。我曾尝试启用额外的日志记录,但没有提供更多详细信息。
I can manually deploy to maven using this command:
我可以使用以下命令手动部署到 maven:
mvn deploy:deploy-file -Durl=http://nexus/content/repositories/libs-snapshots -DrepositoryId=x-repo -DgroupId=com.app -DartifactId=app -Dpackaging=jar -Dversion=0.1-SNAPSHOT -Dfile=D:\app\target\scala-2.10\app_2.10-0.1.jar
Tried using the following publishTo, also without luck
尝试使用以下发布到,也没有运气
publishTo <<= version { v: String =>
val nexus = "http://nexus/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/libs-snapshots")
else
Some("releases" at nexus + "content/repositories/libs-releases")
}
The commands run OK until they need to be authorized, at which point they fail.
命令运行正常,直到它们需要被授权,此时它们会失败。
The Realm in the credentials, does it correspond to the Server Repository ID in maven or the Name? Either or it doesn't work.
凭证中的Realm,是对应maven中的Server Repository ID还是Name?要么不工作。
I've been trying to enable more logging for Ivy, but couldn't get more details.
我一直在尝试为 Ivy 启用更多日志记录,但无法获得更多详细信息。
set ivyLoggingLevel := UpdateLogging.Full
设置 ivyLoggingLevel := UpdateLogging.Full
According to this, there should be further logging:
据此,应该有进一步的日志记录:
I'm behind a internal proxy, so i need to set both HTTP user and HTTPS user and password. Perhaps it's here that it's getting blocked?
我在内部代理后面,所以我需要设置 HTTP 用户和 HTTPS 用户和密码。也许它在这里被阻止了?
any suggestions how to increase the level of ivy logging?
任何建议如何提高常春藤日志记录的级别?
Update
更新
I've got something to work, by using sbt-aether-deployplugin, which uses Maven infrastructure (wagon) to deploy.
我有一些事情要做,通过使用sbt-aether-deploy插件,它使用 Maven 基础设施(货车)进行部署。
Credentials are exactly the same. In fact, the realm didn't seem to matter.
凭据完全相同。事实上,领域似乎并不重要。
following are the lines used:
以下是使用的行:
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
publishTo <<= version { v: String =>
val nexus = "http://nexus/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/libs-snapshots")
else
Some("releases" at nexus + "content/repositories/libs-releases")
}
seq(aetherSettings: _*)
seq(aetherPublishSettings: _*)
Something is not right between the proxy, ivy and nexus.
代理、ivy 和 nexus 之间有些不对劲。
I would still be interested in suggestions to use ivy.
我仍然对使用常春藤的建议感兴趣。
Further update:
进一步更新:
Using
使用
curl -X POST http://nexusUser:nexusPassword@nexus/content/repositories/libs-snapshots -v
I was able to reach the server.
我能够访问服务器。
Same result specifying the proxy to use (it's configured to bypass for local networks, but some java processes like SBT seem to require the headers)
指定要使用的代理的相同结果(它被配置为绕过本地网络,但一些像 SBT 这样的 Java 进程似乎需要标头)
When nexusUser:nexusPassword were not specificied, i was getting the following header:
当 nexusUser:nexusPassword 未指定时,我收到以下标题:
WWW-Authenticate: BASIC realm="Sonatype Nexus Repository Manager"
WWW-Authenticate: BASIC realm="Sonatype Nexus Repository Manager"
effectively that was the issue, the credentials required the name of the Realm to be that exact header, as opposed to other custom repository name like maven defines.
实际上,这就是问题所在,凭据要求 Realm 的名称是确切的标头,而不是像 maven 定义的其他自定义存储库名称。
Many thanks!
非常感谢!
回答by ngarthl
Ivy uses the realm of the WWW-Authenticate header, which will have to match byte-for-byte equal to the one configured in your credentials file.
Ivy 使用 WWW-Authenticate 标头的领域,它必须逐字节匹配与您的凭据文件中配置的相同。
sbt-aether-deploy uses the same header, but uses Aether as its deployment mechanism. Ivy does not.
sbt-aether-deploy 使用相同的标头,但使用 Aether 作为其部署机制。常春藤没有。
The easiest way of figuring out the value of the WWW-Authenticate header is by using cURL.
计算 WWW-Authenticate 标头值的最简单方法是使用 cURL。
curl -X POST http://nexus/content/repositories/libs-snapshots -v > /dev/null
cURL will prompt you for a user and pass.
cURL 将提示您输入用户并通过。
-v will add verbosity so you will be able to see the headers of the request and response.
-v 将添加详细信息,因此您将能够看到请求和响应的标头。
回答by JasonG
I suspect that your credentials file path may be incorrect. Try changing this:
我怀疑您的凭据文件路径可能不正确。尝试改变这个:
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
to that:
对此:
credentials += Credentials("c:/data/user/.sbt/.credentials")
or try directly to troubleshoot first:
或者直接尝试先排除故障:
credentials += Credentials("Sonatype Nexus Repository Manager",
"nexus.scala-tools.org", "admin", "admin123")
If these don't work check that your credentials are valid.
如果这些不起作用,请检查您的凭据是否有效。

