快速解决
所需的凭证需要由 nexus 定义的确切领域。请参阅下面如何找到您定义的那个,但最肯定的是“Sonatype Nexus Repository Manager”。像往常一样将其余详细信息添加到凭据中。
c:/data/user/.sbt/.credentials
realm=Sonatype Nexus Repository Manager
host=nexus
user=repouser
password=password
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")
}
问题
我正在尝试将一个 jar 发布到企业关系回购中。
我可以从 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
realm=X
host=nexus
user=repouser
password=password
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
应用程序/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")
我的 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>
我已按照官方文档和其他各种帖子的说明进行操作,包括 StackOverflow 这样的一个或邮件列表这样的。没有工作。我已尝试启用额外的日志记录,但没有提供更多详细信息。
我可以使用以下命令手动部署到 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
尝试使用以下publishTo,也没有运气
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")
}
这些命令运行正常,直到需要授权,此时它们会失败。
凭证中的Realm,是对应maven中的Server Repository ID还是Name?要么,要么它不起作用。
我一直在尝试为 Ivy 启用更多日志记录,但无法获得更多详细信息。
设置 ivyLoggingLevel := UpdateLogging.Full
据此,应该有进一步的日志记录:
我在内部代理后面,所以我需要设置 HTTP 用户和 HTTPS 用户和密码。也许它在这里被阻塞了?
任何建议如何提高常春藤日志记录的水平?
更新
通过使用sbt-aether-deploy插件,我有一些工作要做,该插件使用 Maven 基础设施 (wagon) 进行部署。
凭证完全相同。事实上,领域似乎并不重要。
以下是使用的行:
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: _*)
代理、常春藤和联结之间有些不对劲。
我仍然会对使用常春藤的建议感兴趣。
进一步更新:
使用
curl -X POST http://nexusUser:nexusPassword@nexus/content/repositories/libs-snapshots -v
我能够到达服务器。
指定要使用的代理的相同结果(它被配置为绕过本地网络,但一些像 SBT 这样的 java 进程似乎需要标头)
当未指定 nexusUser:nexusPassword 时,我得到以下标题:
WWW-Authenticate: BASIC realm="Sonatype Nexus Repository Manager"
实际上这就是问题所在,凭据要求领域的名称是那个确切的标题,而不是像 maven 定义的其他自定义存储库名称。
非常感谢!