样本Play项目缺少或无效依赖

时间:2016-03-01 13:15:28

标签: scala playframework sbt

我正在从https://www.playframework.com/开始在Scala中进行示例Play项目。我已按照视频中的所有步骤操作。但是,当我运行sbt compile时,我收到此错误:

[error] missing or invalid dependency detected while loading class file 'Logging.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'Logging.class' was compiled against an incompatible version of scala.
[error] ScalaWeb/app/views/index.scala.html:5: value addPerson is not a member of controllers.ReverseApplication
[error]     <form action="@routes.Application.addPerson()" method="post">
[error]                                       ^
[error] two errors found
[error] (compile:compileIncremental) Compilation failed

此文件中出现错误:

@(message: String)

@main("Welcome to Play") {

    <form action="@routes.Application.addPerson()" method="post">
        <input name="name" type="text">
        <button>Add Person</button>
    </form>

}

我的build.sbt看起来像这样:

name := """ScalaWeb"""

version := "1.0-SNAPSHOT"

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

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  specs2 % Test,
  "org.sorm-framework" % "sorm" % "0.3.8"
)

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

scalacOptions += "-Ylog-classpath"

application.scala看起来像这样:

package controllers

import models.{DB, Person}
import play.api._
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc._

class Application extends Controller {

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }

  val personForm: Form[Person] = Form {
    mapping (
      "name" -> text
    )(Person.apply)(Person.unapply)
  }

  def addPerson = Action { implicit request =>
    val person = personForm.bindFromRequest.get
    DB.save(person)
    Redirect(routes.Application.index)
  }

}

plugins.sbt就是这样:

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")

// web plugins

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")

addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")

是什么导致这种情况?

1 个答案:

答案 0 :(得分:1)

sorm版本可能存在问题。也许版本0.3.8(从2013年开始非常陈旧)没有为scala版本2.11正确发布。

将sorm更新为以下版本:

<testsuites>
  <testsuite name="all tests" errors="0" failures="2" tests="176468" hostname="tbd" time="1.79972" timestamp="tbd">
    <testcase classname="Test Section" name="Test Name" time="0.000091"/>
    <testcase classname="Test Section" name="Test Name" time="0.000221">
      <failure message="2 &lt;= 1" type="REQUIRE"> 
          at path/path/path path/path/path/file.cpp:106
      </failure>
    </testcase>
    <system-out/>
    <system-err/>
  </testsuite>
</testsuites>

作为参考,请参阅此问题,该问题在很久以前就已修复:

https://github.com/sorm/sorm/issues/34