3

我在单独的模块中提取我的 Scala Swing 应用程序。而且我不想Scala Library在类路径中使用 IDE,因为它还包括 Scala Swing。

我改变了以下classpathentry

<classpathentry
  kind="con"
  path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>

<classpathentry
  sourcepath="C:\Users\wwagner\.ivy2\cache\org.scala-lang\scala-library\srcs\scala-library-2.10.3-sources.jar" 
  kind="lib" 
  path="C:\Users\wwagner\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.10.3.jar"/>

这按预期工作,但我发现 sbteclipse 插件支持classpathTransformerFactories,它可以自动完成。

如何classpathTransformerFactories帮助我处理用例?

4

1 回答 1

0

我必须做的是在我的 Build.scala 中实现以下内容

  // sbteclipse rewrite rules
  object ClasspathentryRewriteRule extends RewriteRule {
    override def transform(parent: Node): Seq[Node] = {
      parent match {
        case c @ <classpathentry/> if (c \ "@path").toString().endsWith("SCALA_CONTAINER") =>
          val home = System.getProperty("user.home")
          val base = s"""$home\\.ivy2\\cache\\org.scala-lang\\scala-library"""
          val srcPath = s"""${base}\\srcs\\scala-library-${D.scalaVersion}-sources.jar"""
          val path = s"""${base}\\jars\\scala-library-${D.scalaVersion}.jar"""
          <classpathentry sourcepath={ srcPath } kind="lib" path={ path }/>
        case other => other
      }
    }
  }

  // sbteclipse transformer
  object ClasspathentryTransformer extends EclipseTransformerFactory[RewriteRule] {
    override def createTransformer(ref: ProjectRef, state: State): Validation[RewriteRule] = {
      ClasspathentryRewriteRule.success
    }
  }

在设置中,以下代码完成了这项工作:

      ....
      EclipseKeys.classpathTransformerFactories := Seq(ClasspathentryTransformer)
      ....
于 2014-03-16T22:51:22.960 回答