1

所以我有一个 Scalatra 应用程序(使用 Scalatra 2.2.1)。我正在使用 Scalate 构建视图;我决定选择 Jade/Markdown 一二。只有一个问题:如果我尝试在翡翠模板中使用降价(以:markdown标签开头),我会得到这个:

scala.Predef$.any2ArrowAssoc(Ljava/lang/Object;)Lscala/Predef$ArrowAssoc;
java.lang.NoSuchMethodError: scala.Predef$.any2ArrowAssoc(Ljava/lang/Object;)Lscala/Predef$ArrowAssoc;

at org.fusesource.scalamd.Markdown$.<init>(md.scala:119)
at org.fusesource.scalamd.Markdown$.<clinit>(md.scala:-1)
at org.fusesource.scalate.filter.ScalaMarkdownFilter$.filter(ScalaMarkdownFilter.scala:32)
at org.fusesource.scalate.RenderContext$class.filter(RenderContext.scala:276)
at org.fusesource.scalate.DefaultRenderContext.filter(DefaultRenderContext.scala:30)
at org.fusesource.scalate.RenderContext$class.value(RenderContext.scala:235)
at org.fusesource.scalate.DefaultRenderContext.value(DefaultRenderContext.scala:30)
at templates.views.$_scalate_$about_jade$.$_scalate_$render(about_jade.scala:37)
at templates.views.$_scalate_$about_jade.render(about_jade.scala:48)
at org.fusesource.scalate.DefaultRenderContext.capture(DefaultRenderContext.scala:92)
at org.fusesource.scalate.layout.DefaultLayoutStrategy.layout(DefaultLayoutStrategy.scala:45)
at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(TemplateEngine.scala:559)
at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply(TemplateEngine.scala:559)
at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply(TemplateEngine.scala:559)

所以这很酷。一旦我删除:markdown标志,错误就会消失,除此之外,一切都会编译(除了 markdown 没有正确呈现)。

到目前为止我知道和发现的事情:

  1. 有人认为这个错误是构建中某个地方不兼容的 Scala 版本的副产品。我的 build.scala 将 Scala 版本定义为 Scalatra 明确兼容的 2.10.0。
  2. ...也就是说,我不知道哪个版本的 Scalate Scalatra 引入,并且我尝试覆盖它到目前为止还没有奏效。我知道当前稳定的 Scalate (1.6.1) 只兼容 Scala 2.10.0——但这就是我正在使用的。
  3. 但是,我确信我的类路径是干净的。我没有冲突的 Scala 版本。依赖项中的所有内容都是 2.10.0。

以前有人用过这个吗?有任何想法吗?

编辑

根据请求,这是我的构建定义:

//build.sbt 
libraryDependencies += "org.scalatest" %% "scalatest" % "2.0.M5b" % "test"                                                                                                                                     
                                                                                                                                                                                                           
libraryDependencies += "org.twitter4j" % "twitter4j-core" % "3.0.3"                                                                                                                                            
                                                                                                                                                                                                           
libraryDependencies += "org.fusesource.scalamd" % "scalamd" % "1.5" 

//build.properties
sbt.version=0.12.3

//build.scala
import sbt._                                                                                                                                                                                                   
import Keys._                                                                                                                                                                                                  
import org.scalatra.sbt._                                                                                                                                                                                      
import org.scalatra.sbt.PluginKeys._                                                                                                                                                                           
import com.mojolly.scalate.ScalatePlugin._                                                                                                                                                                     
import ScalateKeys._                                                                                                                                                                                           
                                                                                                                                                                                                               
object TheRangeBuild extends Build {                                                                                                                                                                           
  val Organization = "com.gastove"                                                                                                                                                                             
  val Name = "The Range"                                                                                                                                                                                       
  val Version = "0.1.0-SNAPSHOT"                                                                                                                                                                               
  val ScalaVersion = "2.10.0"                                                                                                                                                                                  
  val ScalatraVersion = "2.2.1"                                                                                                                                                                                
                                                                                                                                                                                                               
  lazy val project = Project (                                                                                                                                                                                 
    "the-range",                                                                                                                                                                                               
    file("."),                                                                                                                                                                                                 
    settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(                                                                                                        
      organization := Organization,                                                                                                                                                                            
      name := Name,                                                                                                                                                                                            
      version := Version,                                                                                                                                                                                      
      scalaVersion := ScalaVersion,                                                                                                                                                                            
      resolvers += Classpaths.typesafeReleases,                                                                                                                                                                
      libraryDependencies ++= Seq(                                                                                                                                                                             
        "org.scalatra" %% "scalatra" % ScalatraVersion,                                                                                                                                                        
        "org.scalatra" %% "scalatra-scalate" % ScalatraVersion,                                                                                                                                                
        "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",                                                                                                                                        
        "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",                                                                                                                                            
        "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "compile;container",                                                                                                                        
        "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "compile;container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))                                            
      ),                                                                                                                                                                                                       
      scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base =>                                                                                                                               
        Seq(                                                                                                                                                                                                   
          TemplateConfig(                                                                                                                                                                                      
            base / "webapp" / "WEB-INF" / "templates",                                                                                                                                                         
            Seq.empty,  /* default imports should be added here */                                                                                                                                             
            Seq(                                                                                                                                                                                               
              Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true)                                                                                 
            ),  /* add extra bindings here */                                                                                                                                                                  
            Some("templates")                                                                                                                                                                                  
          )                                                                                                                                                                                                    
        )                                                                                                                                                                                                      
      }                                                                                                                                                                                                        
    ) ++ seq(com.typesafe.startscript.StartScriptPlugin.startScriptForClassesSettings: _*)                                                                                                                     
  )                                                                                                                                                                                                            
}
4

2 回答 2

1

使用markdown 过滤器时,需要添加 scalamd 库作为运行时依赖项:

"org.fusesource.scalamd" %% "scalamd" % "1.6"

最新版本可以在Maven Central上找到

您也可以删除build.sbt文件并将依赖项放入build.scala文件中,这会使事情变得更简单。

import sbt._
import Keys._
import org.scalatra.sbt._
import org.scalatra.sbt.PluginKeys._
import com.mojolly.scalate.ScalatePlugin._
import ScalateKeys._
object TheRangeBuild extends Build {
  val Organization = "com.gastove"
  val Name = "The Range"
  val Version = "0.1.0-SNAPSHOT"
  val ScalaVersion = "2.10.0"
  val ScalatraVersion = "2.2.1"
  lazy val project = Project(
    "the-range",
    file("."),
    settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
      organization := Organization,
      name := Name,
      version := Version,
      scalaVersion := ScalaVersion,
      resolvers += Classpaths.typesafeReleases,
      libraryDependencies ++= Seq(  // adding this Seq to the libraryDependencies
        "org.scalatra" %% "scalatra" % ScalatraVersion,
        "org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
        "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
        "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
        "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "compile;container",
        "org.scalatest" %% "scalatest" % "2.0.M5b" % "test",
        "org.twitter4j" % "twitter4j-core" % "3.0.3",
        "org.fusesource.scalamd" % "scalamd" % "1.6",
        "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "compile;container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))
      ),
      scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base =>
        Seq(
          TemplateConfig(
            base / "webapp" / "WEB-INF" / "templates",
            Seq.empty,  /* default imports should be added here */
            Seq(
              Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true)
            ),  /* add extra bindings here */
            Some("templates")
          )
        )
      }
    ) ++ seq(com.typesafe.startscript.StartScriptPlugin.startScriptForClassesSettings: _*)
  )
}
于 2013-08-31T21:56:50.893 回答
1

这来自:

libraryDependencies += "org.fusesource.scalamd" % "scalamd" % "1.5" 

查看scalamd-1.5 pom.xml,它是针对 Scala 2.8.1 构建的,与 2.10 不兼容。

依赖关系解析保留 2.10 并丢弃 2.8.1 依赖关系,您最终会遇到这个类路径问题。

您唯一的解决方案是尝试针对 Scala 2.10 构建一个新的 scalamd 版本,可能会修复一些问题以实现它,然后发布它(至少在本地发布)。

于 2013-09-01T22:54:00.410 回答