简体   繁体   English

尽管发布成功,但未指定“用于发布的存储库”

[英]“Repository for publishing is not specified” despite publishing succeeding

I have a separate Settings.scala file in my large SBT project which has the following: 我的大型SBT项目中有一个单独的Settings.scala文件,其中包含以下内容:

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: 现在我在build.sbt中的所有项目都定义如下:

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: 我看到我的所有工件都已发布,当我查看我的Nexus时,他们就在那里,我也可以将它们用作依赖项等,所以发布工作,但是我最后得到以下内容:

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? 在我的sbt文件中我错过了什么/做错了什么?

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. 如果没有为构建中的根目录定义项目,则sbt会创建一个聚合构建中所有其他项目的默认项目。

I suspect you don't define a root project, so SBT defines its own and of course it doesn't get the common settings. 我怀疑你没有定义一个根项目,所以SBT定义了它自己,当然它没有得到常见的设置。 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. 使用+ publish SBT尝试发布它,首先发布它聚合的所有项目(成功),然后无法发布聚合项目本身。

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 ); 只需定义根项目并明确地提供所需的设置(它们不一定相同:实际上没有任何内容可以在那里发布,所以你可能想要publishArtifact := false );

  2. Make the settings global : 使设置全局

     publishTo in ThisBuild := ... 

See also What is the difference between ThisBuild and Global scopes? 另请参见ThisBuild和Global范围之间的区别?

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. 不幸的是建立地方publishArtifact := false并不妨碍发布(如使用publishSigned从SBT-PGP插件),你仍然可以得到root/*:publishSignedConfiguration) Repository for publishing is not specified的错误。

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). SBT问题3136建议skip in publish := true是截至2017年10月禁用项目中所有发布活动的更好设置(SBT 1.0.3)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM