简体   繁体   English

Sbt 生成的 docker 容器无法 package 子项目

[英]Sbt generated docker container fails to package subproject

I have a multi-project build.sbt file, with projects like so:我有一个多项目 build.sbt 文件,项目如下:

lazy val utils = (project in file("utils"))
  .settings(
    Seq(
      publishArtifact := false
    )).[...]


lazy val api = (project in file("api"))
  .dependsOn(utils)
  .settings(commonSettings: _*)
  .enablePlugins(JavaAppPackaging, DockerPlugin)
  .settings(publish := {})
  .settings(
    Seq(
      packageName in Docker := "my-api",
      dockerBaseImage := "java:8",
      mainClass in Compile := Some("com.path.to.Main"),
      publishArtifact := false,
      unmanagedJars in Compile += file("jars/somejars.jar")
    ))

API is built on top of Finch framework. API 建立在 Finch 框架之上。 I create a docker image for the API using sbt api/docker:publishLocal and then run it locally.我使用sbt api/docker:publishLocal为 API 创建了 docker 映像,然后在本地运行它。 However, it seems like the utils subproject classes are not packaged with the final container, and as a result I am getting multiple但是,似乎utils子项目类没有与最终容器打包在一起,因此我得到了多个

java.lang.ClassNotFoundException:

types of exceptions.异常类型。 For a similar project that doesn't have a subproject dependency, everything runs smoothly and I have no problems.对于没有子项目依赖的类似项目,一切运行顺利,我没有任何问题。

Am I missing something in the plugin configuration?我在插件配置中遗漏了什么吗? I thought .dependsOn() should be taking care of providing dependent classes in the project docker image.我认为.dependsOn()应该负责在项目 docker 图像中提供依赖类。

Answering my own question, but turns out this is a default behaviour of sbt-native-packager , or rather sbt , when a dependent project has publishArtifact:= false setting.回答我自己的问题,但事实证明这是sbt-native-packager的默认行为,或者更确切地说是sbt ,当依赖项目具有publishArtifact:= false设置时。

A workaround that worked for me was changing the above to publish/skip:= true .对我有用的解决方法是将上面的内容更改为publish/skip:= true

More on this issue can be found here: https://github.com/sbt/sbt-native-packager/issues/1221关于这个问题的更多信息可以在这里找到: https://github.com/sbt/sbt-native-packager/issues/1221

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

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