为什么发布插件项目因RuntimeException而失败:未指定用于发布的存储库?

时间:2014-10-10 09:46:22

标签: sbt

我正在尝试将SBT插件发布到存储库。我不确定这是否有任何相关性,但我们的插件会加载sbt-twirl插件 - Google搜索,似乎可能会覆盖publishConfiguration:

new PublishConfiguration(None, "dotM2", arts, Seq(), level)

当我运行发布任务时,工件会部署到repo,但sbt任务会失败:

sbt (my-sbt-plugin)> publish
[info] Loading global plugins from ...
...
[info] Done packaging.
[info]  published sbt-my-sbt-plugin to http://my.repo.com/.../sbt-my-sbt-plugin-0.1-SNAPSHOT.jar
java.lang.RuntimeException: Repository for publishing is not specified. 
     .... stack trace here ....
[error] (my-sbt-plugin/*:publishConfiguration) Repository for publishing is not specified.

导致错误的原因是什么,以及如何阻止发布失败?

**更新**以下是inspect publish

sbt (my-sbt-plugin)> inspect publish                                                                                                                   
[info] Task: Unit                                                                                                                                            
[info] Description:                                                                                                                                          
[info]  Publishes artifacts to a repository.                                                                                                                 
[info] Provided by:                                                                                                                                          
[info]  {file:/path/to/my-sbt-plugin/}my-sbt-plugin/*:publish                                                                    
[info] Defined at:                                                                                                                                           
[info]  (sbt.Classpaths) Defaults.scala:988                                                                                                                  
[info] Dependencies:                                                                                                                                         
[info]  my-sbt-plugin/*:ivyModule                                                                                                                      
[info]  my-sbt-plugin/*:publishConfiguration                                                                                                           
[info]  my-sbt-plugin/*:publish::streams                                                                                                               
[info] Delegates:                                                                                                                                            
[info]  my-sbt-plugin/*:publish                                                                                                                        
[info]  {.}/*:publish                                                                                                                                        
[info]  */*:publish                                                                                                                                          
[info] Related:                                                                                                                                              
[info]  plugin/*:publish 

以下是我配置发布的方式(包含一些插件设置,不包括libraryDependencies和1或2个其他设置)

lazy val plugin = project
  .settings(publishSbtPlugin: _*)
  .settings(
    name := "my-sbt-plugin",
    sbtPlugin := true,
    addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.2")
  )

def publishSbtPlugin = Seq(
  publishMavenStyle := true,
  publishTo := {
    val myrepo = "http://myrepo.tld/"
    if (isSnapshot.value) Some("The Realm" at myrepo + "snapshots")
    else Some("The Realm" at myrepo + "releases")
  },
  credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
)

3 个答案:

答案 0 :(得分:3)

tl; dr 不要使用lazy val plugin = project来定义项目(原因不明)

经过一些评论后发现问题是使用plugin定义的项目名称lazy val plugin = project。似乎名称​​以某种方式保留。将项目名称更改为plugin以外的任何其他名称,然后重新开始。

答案 1 :(得分:2)

指定“插件”以外的项目名称解决了该问题。我通过删除一个项目中的冗余build.sbt简化了构建定义,并且只是在项目目录中使用完整的构建定义。承载多项目构建的根项目也被重新配置为不发布:

lazy val root =
  Project("sbt-my-plugin-root", file("."))
    .settings(noPublishing: _*)
    .aggregate(sbtMyPluginModule)

lazy val sbtMyPluginModule =
  Project("sbt-my-plugin-module", file("sbt-my-plugin-module"))
    .settings(publishSbtPlugin: _*)
    .settings(
      name := "sbt-my-plugin-module",
      organization := "com.my.org",
      sbtPlugin := true
    )

lazy val noPublishing = seq(
  publish := (),
  publishLocal := ()
)

lazy val publishSbtPlugin = Seq(
  publishMavenStyle := true,
  publishArtifact in Test := false,
  publishTo := {
    val myrepo = "http://myrepo.tld/"
    if (isSnapshot.value) Some("The Realm" at myrepo + "snapshots")
    else Some("The Realm" at myrepo + "releases")
  },
  credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
)

答案 2 :(得分:1)

如果您在本地尝试此操作,请按以下方式使用publishLocal(不是publish):

sbt clean compile publish-local