【问题标题】:Why does enablePlugins(DockerPlugin) from sbt-docker in Play project give "error: reference to DockerPlugin is ambiguous"?为什么 Play 项目中 sbt-docker 的 enablePlugins(DockerPlugin) 给出“错误:对 DockerPlugin 的引用不明确”?
【发布时间】:2016-02-24 06:41:12
【问题描述】:

我正在尝试 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。

【问题讨论】:

    标签: scala build docker sbt sbt-docker


    【解决方案1】:

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

    enablePlugins(sbtdocker.DockerPlugin)
    

    【讨论】:

      【解决方案2】:

      正如消息中所说的 "and import _root_.com.typesafe.sbt.packager.docker.DockerPlugin" sbt-native-packager 带有冲突的 DockerPlugin 类。但这就是你已经知道的。

      诀窍在于 Play 插件依赖于 sbt-native-packager 来...缓解人们的生活,从而缓解冲突(抱歉,太多的帮助可能会破坏人们的生活 :))。

      一种解决方案是使用完全限定的插件类名,如@pfn 推荐或disablePlugins(SbtNativePackager)

      http://www.scala-sbt.org/sbt-native-packager/topics/play.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-21
        • 2018-05-18
        • 2014-10-22
        • 2017-11-09
        • 2015-10-11
        • 2014-08-15
        • 2020-12-22
        • 1970-01-01
        相关资源
        最近更新 更多