Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sbt

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")
)
like image 627
Brett Avatar asked Oct 10 '14 09:10

Brett


3 Answers

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.

like image 138
Jacek Laskowski Avatar answered Apr 28 '23 16:04

Jacek Laskowski


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")
)
like image 43
Brett Avatar answered Apr 28 '23 16:04

Brett


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

sbt clean compile publish-local
like image 24
GKV Avatar answered Apr 28 '23 17:04

GKV