How to have sbt multi-project builds configure setting for subprojects?

廉价感情. 提交于 2019-12-23 01:52:43

问题


I have an sbt (0.13.1) project with a bunch of subprojects. I am generating eclipse project configurations using sbteclipse. My projects only have scala source files, so I want to remove the generated src/java folders.

I can achieve that by (redundantly) adding the following to the build.sbt of each subproject:

unmanagedSourceDirectories in Compile := (scalaSource in Compile).value :: Nil

unmanagedSourceDirectories in Test := (scalaSource in Test).value :: Nil

I tried just adding the above configuration to the root build.sbt but the eclipse command still generated the java source folders.

Is there any way to specify a configuration like this once (in the root build.sbt) and have it flow down to each subproject?


回答1:


You could define the settings unscoped and then reuse them

val onlyScalaSources = Seq(
  unmanagedSourceDirectories in Compile := Seq((scalaSource in Compile).value),
  unmanagedSourceDirectories in Test := Seq((scalaSource in Test).value)
)

val project1 = project.in( file( "project1" )
  .settings(onlyScalaSources: _*)

val project2 = project.in( file( "project2" )
  .settings(onlyScalaSources: _*)

You could also create a simple plugin (untested code)

object OnlyScalaSources extends AutoPlugin {
  override def trigger = allRequirements
  override lazy val projectSettings = Seq(
    unmanagedSourceDirectories in Compile := Seq((scalaSource in Compile).value),
    unmanagedSourceDirectories in Test := Seq((scalaSource in Test).value)
  )
}

More details about creating plugins in the plugins documentation



来源:https://stackoverflow.com/questions/26809331/how-to-have-sbt-multi-project-builds-configure-setting-for-subprojects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!