【问题标题】:Why does publishing plugin project fail with RuntimeException: Repository for publishing is not specified?为什么发布插件项目失败并出现 RuntimeException:未指定发布存储库?
【发布时间】:2014-12-05 10:48:42
【问题描述】:

我正在尝试将 SBT 插件发布到存储库。我不确定这是否有任何相关性,但我们的插件加载了 sbt-twirl 插件 - 谷歌搜索,似乎 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")
)

【问题讨论】:

    标签: sbt


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      指定“插件”以外的项目名称解决了该问题。我通过删除 1 个项目中的冗余 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")
      )
      

      【讨论】:

        【解决方案3】:

        如果您在本地尝试此操作,请使用publishLocal(不是publish),如下所示:

        sbt clean compile publish-local
        

        【讨论】:

          猜你喜欢
          • 2016-03-04
          • 2016-07-30
          • 1970-01-01
          • 1970-01-01
          • 2016-12-29
          • 1970-01-01
          • 1970-01-01
          • 2015-11-26
          • 2020-10-22
          相关资源
          最近更新 更多