Why does publishing plugin project fail with RuntimeException: Repository for publishing is not specified?

▼魔方 西西 提交于 2019-12-22 04:39:26

问题


I am trying to publish an SBT plugin to a repository. I'm not sure if this has any relevance, but our plugin loads the sbt-twirl plugin - Googling around, it seems like publishConfiguration might be overriden:

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

When I run the publish task, artifacts are deployed to the repo, but the sbt task then fails:

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.

What is causing the error, and what could I do to stop the publishing from failing?

** Update ** Here is 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 

Here's how I've configured publishing (with some of the plugin settings, excluding libraryDependencies and 1 or 2 other settings)

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")
)

回答1:


tl;dr Don't use lazy val plugin = project to define a project (for unknown yet reasons)

After few comments it turned out that the issue was that the name of the project plugin as defined using lazy val plugin = project. It seems that the name is somehow reserved. Change the project's name to any other name than plugin and start over.




回答2:


Specifying a project name other than "plugin" resolved the issue. I simplified the build definition a bit by removing a redundant build.sbt in 1 of the projects and am just using a full build definition in project directory. The root project that hosts the multi-project build is also reconfigured for no publishing:

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:


if you trying this on your local then use publishLocal (not publish) as follows:

sbt clean compile publish-local


来源:https://stackoverflow.com/questions/26296493/why-does-publishing-plugin-project-fail-with-runtimeexception-repository-for-pu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!