scala - 为什么 Play 项目中 sbt-docker 的 enablePlugins(DockerPlugin) 会给出 "error: reference to DockerPlugin is ambiguous"?

标签 scala build docker sbt sbt-docker

我正在尝试 dockerize 一个 play web 应用程序,我正在使用 sbt-docker。当我执行 sbt docker 时,我得到了一个令人毛骨悚然的错误:

error: reference to DockerPlugin is ambiguous;
it is imported twice in the same scope by
import _root_.sbtdocker.DockerPlugin
and import _root_.com.typesafe.sbt.packager.docker.DockerPlugin
enablePlugins(DockerPlugin)
              ^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

我收到上述错误,我的 build.sbt 看起来像这样:

enablePlugins(DockerPlugin)

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  specs2 % Test
)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator

// Make docker depend on the package task, which generates a jar file of the application code
docker <<= docker.dependsOn(sbt.Keys.`package`.in(Compile, packageBin))

// Define a Dockerfile
dockerfile in docker := {
  val jarFile = artifactPath.in(Compile, packageBin).value
  val classpath = (managedClasspath in Compile).value
  val mainclass = mainClass.in(Compile, packageBin).value.getOrElse(sys.error("Expected exactly one main class"))
  val jarTarget = s"/app/${jarFile.getName}"
  // Make a colon separated classpath with the JAR file
  val classpathString = classpath.files.map("/app/" + _.getName).mkString(":") + ":" + jarTarget
  new Dockerfile {
    // Base image
    from("java")
    // Add all files on the classpath
    add(classpath.files, "/app/")
    // Add the JAR file
    add(jarFile, jarTarget)
    // On launch run Java with the classpath and the main class
    entryPoint("java", "-cp", classpathString, mainclass)
  }
}

我怀疑 sbt-native-packager 与 sbt-docker 冲突。但我没有在任何地方导入 sbt-native-packager。

最佳答案

如果有冲突,则使用全名。

enablePlugins(sbtdocker.DockerPlugin)

关于scala - 为什么 Play 项目中 sbt-docker 的 enablePlugins(DockerPlugin) 会给出 "error: reference to DockerPlugin is ambiguous"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33849346/

相关文章:

scala - ClassNotFoundException : org. apache.spark.repl.SparkCommandLine

scala - 类型和泛型 : difference between `[X <: Int]` and `{type X <: Int }`

docker - 测试 Docker Compose 配置是否启动的正确方法?

docker - 使用 docker compose 为 Ninja 开具发票 - 错误 500

scala - Spark和Scala,通过映射公共(public)键添加具有来自另一个数据帧的值的新列

java - 如何在外部组件上发生事件时立即检测到该事件。不想投票,还有其他选择吗?

eclipse - 如何导入gradle项目

java - 如何使用 Nexus 存储库解决 Maven 中的依赖关系错误

c++ - 可以为他/她没有的设备预编译 opencl 内核吗?

python - docker:无法将两个容器端口映射到一个主机端口