sbt:未经授权发布到公司Nexus存储库

fra*_*cca 22 scala nexus ivy maven sbt

快速解决

所需的凭证需要nexus定义的确切领域.请参阅下文,了解如何找到您定义的那个,但肯定是"Sonatype Nexus Repository Manager".正常情况下,将其余详细信息添加到凭据.

C:/data/user/.sbt/.credentials

realm=Sonatype Nexus Repository Manager
host=nexus
user=repouser
password=password
Run Code Online (Sandbox Code Playgroud)

build.sbt 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")
  }
Run Code Online (Sandbox Code Playgroud)

问题

我正在尝试将jar发布到公司的nexus repo中.

我可以从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
Run Code Online (Sandbox Code Playgroud)

C:/data/user/.sbt/.credentials

realm=X 
host=nexus
user=repouser
password=password
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

应用程序/ 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")
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

我按照指示,从官方文档等各个岗位,包括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
Run Code Online (Sandbox Code Playgroud)

尝试使用以下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")
  }
Run Code Online (Sandbox Code Playgroud)

命令运行正常,直到需要授权,此时它们会失败.

凭据中的域,它是否与maven中的服务器存储库ID或名称相对应?要么它不起作用.

我一直在尝试为Ivy启用更多日志记录,但无法获得更多详细信息.

设置ivyLoggingLevel:= UpdateLogging.Full

根据这个,应该进一步记录:

https://svn.apache.org/repos/asf/ant/ivy/core/tags/2.2.0/src/java/org/apache/ivy/util/url/IvyAuthenticator.java

我是一个内部代理,所以我需要设置HTTP用户和HTTPS用户和密码.也许它在这里被封锁了?

有什么建议如何提高常春藤伐木的水平?


更新

我有一些工作,使用sbt-aether-deploy插件,它使用Maven基础设施(旅行车)进行部署.

凭证完全相同.事实上,这个领域似乎并不重要.

以下是使用的行:

    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: _*)
Run Code Online (Sandbox Code Playgroud)

代理,常春藤和nexus之间的东西不对.

我仍然对使用常春藤的建议感兴趣.


进一步更新:

运用

curl -X POST http://nexusUser:nexusPassword@nexus/content/repositories/libs-snapshots -v
Run Code Online (Sandbox Code Playgroud)

我能够到达服务器.

指定要使用的代理的相同结果(它被配置为绕过本地网络,但是某些Java进程(如SBT)似乎需要标头)

当nexusUser:nexusPassword没有具体说明时,我得到以下标题:

WWW-Authenticate:BASIC realm ="Sonatype Nexus Repository Manager"

有效的问题是,凭证要求Realm的名称是精确的标题,而不是像maven定义的其他自定义存储库名称.

非常感谢!

nga*_*thl 24

Ivy使用WWW-Authenticate标头的领域,它必须与您的凭证文件中配置的字节匹配.

sbt-aether-deploy使用相同的头,但使用Aether作为其部署机制.常春藤没有.

确定WWW-Authenticate标头值的最简单方法是使用cURL.

curl -X POST http://nexus/content/repositories/libs-snapshots -v > /dev/null
Run Code Online (Sandbox Code Playgroud)

cURL会提示您输入用户并通过.

-v将添加详细程度,以便您能够看到请求和响应的标头.

  • 另一个非常重要的注意事项是凭证文件中的主机只需要是Nexus服务器的IP或域名.如果包含端口,则不会选择凭据. (5认同)