21

I have a separate Settings.scala file in my large SBT project which has the following:

lazy val commonSettings = Seq(
  // ... lots of settings
  publishTo :=
    Some("Sonatype Nexus Repository Manager" at
      "http://my.company.nexus/content/repositories/releases/"),
  credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
  publishMavenStyle := true,
  crossScalaVersions := Seq("2.10.6"),
  // ... lots of other settings
)

Now all my projects in build.sbt are defined the following:

lazy val aProject =
  project.in(file("somewhere/aProject")).
    settings(commonSettings).
    settings(
      // project specific settings
    )

When I now do

sbt "+ publish"

I see that all my artifacts get published, and when I look into my Nexus they are there, and I can also use them as dependencies etc, so publishing works, but nevertheless I get the following at the end:

java.lang.RuntimeException: Repository for publishing is not specified.
    at scala.sys.package$.error(package.scala:27)
    at sbt.Classpaths$$anonfun$getPublishTo$1.apply(Defaults.scala:1470)
    at sbt.Classpaths$$anonfun$getPublishTo$1.apply(Defaults.scala:1470)
    at scala.Option.getOrElse(Option.scala:120)
    at sbt.Classpaths$.getPublishTo(Defaults.scala:1470)
    at sbt.Classpaths$$anonfun$59.apply(Defaults.scala:1150)
    at sbt.Classpaths$$anonfun$59.apply(Defaults.scala:1150)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

What am I missing / doing wrong in my sbt file?

rabejens
  • 7,594
  • 11
  • 56
  • 104

2 Answers2

30

If a project is not defined for the root directory in the build, sbt creates a default one that aggregates all other projects in the build.

I suspect you don't define a root project, so SBT defines its own and of course it doesn't get the common settings. With + publish SBT tries to publish it, starts with publishing all the projects it aggregates (which succeeds) and then fails to publish the aggregate project itself.

To fix this, either:

  1. just define the root project and give the desired settings explicitly (and they aren't necessarily the same: there is nothing actually to publish there, so you probably want publishArtifact := false);

  2. Make the settings global:

    publishTo in ThisBuild := ...
    

See also What is the difference between ThisBuild and Global scopes?

Community
  • 1
  • 1
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • OK, so I have to define a root project. Now my project has a big, BIG bunch of subproject. How can I avoid writing `lazy val root = project.in(file(".")).aggregate(project1, project2, project3, ..., project739672)`? Is there an "aggregate all" method? – rabejens Dec 01 '15 at 07:20
  • I now added a root project and constructed the large `aggregate` using a shell script. – rabejens Dec 01 '15 at 07:34
  • Sorry, I don't know. You should ask it as a separate question. I've added an alternative which doesn't require defining the root project explicitly, provided you want to apply default settings there. – Alexey Romanov Dec 01 '15 at 07:35
  • I asked a separate question, and mark your answer as accepted because it did the trick. Thank you. – rabejens Dec 01 '15 at 08:15
  • `ThisBuild / publishTo` (formerly `publishTo in ThisBuild`) did the trick in my case. – 6infinity8 Mar 29 '22 at 13:17
  • Only setting `publish := {}` in the root project solved this for me. None of the above (/or below) – Hunor Kovács Oct 16 '22 at 00:30
10

Unfortunately there are builds where publishArtifact := false doesn't prevent publishing (such as using publishSigned from sbt-pgp plugin) and you can still get root/*:publishSignedConfiguration) Repository for publishing is not specified errors.

SBT issue 3136 suggests skip in publish := true is a better setting for disabling all publishing activity in a project as of Oct 2017 (SBT 1.0.3).

Ben Hutchison
  • 2,433
  • 2
  • 21
  • 25