我正在为scalac编写一个nsc插件。该项目由3个不同的模块组成:
我的build.sbt文件是
import sbt._
import Keys._
lazy val sharedSettings = Defaults.coreDefaultSettings ++ Seq(
scalaVersion := "2.12.1",
organization := "localhost",
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked")
)
lazy val usePluginSettings = Seq(
scalacOptions ++= {
val jar = (Keys.`package` in (plugin, Compile)).value
val addPlugin = "-Xplugin:" + jar.getAbsolutePath
val dummy = "-Jdummy=" + jar.lastModified
Seq(addPlugin, dummy)
}
)
lazy val main = Project(
id = "main",
base = file("."),
aggregate = Seq(plugin, core, samples)
)
lazy val core = Project(
id = "core",
base = file("core")
) settings (
sharedSettings: _*
) settings (
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.4.17"
)
lazy val plugin = Project(
id = "typestate",
base = file("plugin")
) settings (
sharedSettings: _*
) settings (
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
) dependsOn (core)
lazy val samples = Project(
id = "samples",
base = file("samples")
) settings (
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.4.17"
) settings (
sharedSettings ++ usePluginSettings: _*
) dependsOn (core)
现在,当我尝试编译模块 samples 时,我得到一个java.lang.NoClassDefFoundError
,其中引用了 core 模块中的类。但是,当删除usePluginSettings
时,可以编译模块而不会出现任何错误。
据我所知,问题是由插件jar中缺少的核心工件引起的。我试图将sbt-assembly任务添加到构建中以获得一个胖子,但我没有成功。
有没有人有解决方案?