我在单独的模块中提取Scala Swing应用程序。我不想在类路径中有来自IDE的Scala Library
,因为它还包括Scala Swing。
我更改了以下classpathentry
<classpathentry
kind="con"
path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry
sourcepath="C:Userswwagner.ivy2cacheorg.scala-langscala-librarysrcsscala-library-2.10.3-sources.jar"
kind="lib"
path="C:Userswwagner.ivy2cacheorg.scala-langscala-libraryjarsscala-library-2.10.3.jar"/>
按预期工作,但我发现sbteclipse插件支持classpathTransformerFactories
,它可以自动完成。
classpathTransformerFactories
如何帮助我用例?
我要做的是在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)
....