Intellij SBT 项目:如何更改内容根目录?
Intellij SBT project: How to change the content roots?
这是我项目中当前的内容根配置:
但是,我希望 "scala" 目录是实际测试内容的根目录,而不是名为 "test" 的目录。如果我修改它,我会收到 "Module is imported from Sbt. Any changes in its configuration will may be lost after re-importing." 的警告(事实上,它们是)。
不幸的是,我找不到在我的 Build.scala 文件(或任何其他文件)中声明此配置的位置。我能做些什么来一劳永逸地说服 IntelliJ "scala" 是正确的测试内容根?
这是我的 Build.scala 文件(如果重要的话,这是一个 Play 2.5.4 项目):
import play.routes.compiler.StaticRoutesGenerator
import play.sbt.PlayScala
import play.sbt.routes.RoutesKeys._
import sbt.Keys._
import sbt._
object Build extends Build {
val main = Project("Mp3Streamer", file(".")).enablePlugins(PlayScala).settings(
scalaVersion := "2.11.8",
version := "1.0-SNAPSHOT",
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),
libraryDependencies ++= Seq(
// a bunch of dependencies
),
resolvers += Resolver.mavenLocal,
javaOptions ++= Seq("-Xmx4000M", "-Xms2024M", "-XX:MaxPermSize=2000M"),
routesGenerator := StaticRoutesGenerator
)
}
通过将 scalaSource in Test := baseDirectory.value / "test" "/scala",
添加到我的 Build.scala 文件,我已经能够将 "scala" 文件夹设为测试源,但父 "test" 文件夹仍然也是测试来源:
据我所知,这是从 Play 继承的设置,因为如果我删除 .enablePlugins(PlayScala)
代码,"test" 文件夹将不再是测试源。按照https://www.playframework.com/documentation/2.5.x/Anatomy#Default-SBT-layout, I disabled the play layout, and then manually added the source and resource directories, which I copied from https://github.com/playframework/playframework/blob/master/framework/src/sbt-plugin/src/main/scala/play/sbt/PlayLayoutPlugin.scala#L9中的说明,只修改测试源,添加我自己的资源文件夹。我修改后的 Build.scala 文件现在是:
val main = Project("Mp3Streamer", file("."))
.enablePlugins(PlayScala)
.disablePlugins(PlayLayoutPlugin)
.settings(
target := baseDirectory.value / "target",
sourceDirectory in Compile := baseDirectory.value / "app",
// My change
sourceDirectory in Test := baseDirectory.value / "test" / "scala",
resourceDirectory in Compile := baseDirectory.value / "conf",
scalaSource in Compile := baseDirectory.value / "app",
// My change
scalaSource in Test := baseDirectory.value / "test" / "scala",
// I've added this resource
resourceDirectory in Test := baseDirectory.value / "test" / "resources",
javaSource in Compile := baseDirectory.value / "app",
sourceDirectories in(Compile, TwirlKeys.compileTemplates) := Seq((sourceDirectory in Compile).value),
sourceDirectories in(Test, TwirlKeys.compileTemplates) := Seq((sourceDirectory in Test).value),
// sbt-web
sourceDirectory in Assets := (sourceDirectory in Compile).value / "assets",
sourceDirectory in TestAssets := (sourceDirectory in Test).value / "assets",
resourceDirectory in Assets := baseDirectory.value / "public",
// Native packager
sourceDirectory in Universal := baseDirectory.value / "dist",
// Everything else is the same as the original Build.scala file
老实说,这感觉太老套了,我可能最终会修改我的目录结构以匹配 Play 的默认设置...但重要的是原则!
这是我项目中当前的内容根配置:
但是,我希望 "scala" 目录是实际测试内容的根目录,而不是名为 "test" 的目录。如果我修改它,我会收到 "Module is imported from Sbt. Any changes in its configuration will may be lost after re-importing." 的警告(事实上,它们是)。
不幸的是,我找不到在我的 Build.scala 文件(或任何其他文件)中声明此配置的位置。我能做些什么来一劳永逸地说服 IntelliJ "scala" 是正确的测试内容根?
这是我的 Build.scala 文件(如果重要的话,这是一个 Play 2.5.4 项目):
import play.routes.compiler.StaticRoutesGenerator
import play.sbt.PlayScala
import play.sbt.routes.RoutesKeys._
import sbt.Keys._
import sbt._
object Build extends Build {
val main = Project("Mp3Streamer", file(".")).enablePlugins(PlayScala).settings(
scalaVersion := "2.11.8",
version := "1.0-SNAPSHOT",
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),
libraryDependencies ++= Seq(
// a bunch of dependencies
),
resolvers += Resolver.mavenLocal,
javaOptions ++= Seq("-Xmx4000M", "-Xms2024M", "-XX:MaxPermSize=2000M"),
routesGenerator := StaticRoutesGenerator
)
}
通过将 scalaSource in Test := baseDirectory.value / "test" "/scala",
添加到我的 Build.scala 文件,我已经能够将 "scala" 文件夹设为测试源,但父 "test" 文件夹仍然也是测试来源:
据我所知,这是从 Play 继承的设置,因为如果我删除 .enablePlugins(PlayScala)
代码,"test" 文件夹将不再是测试源。按照https://www.playframework.com/documentation/2.5.x/Anatomy#Default-SBT-layout, I disabled the play layout, and then manually added the source and resource directories, which I copied from https://github.com/playframework/playframework/blob/master/framework/src/sbt-plugin/src/main/scala/play/sbt/PlayLayoutPlugin.scala#L9中的说明,只修改测试源,添加我自己的资源文件夹。我修改后的 Build.scala 文件现在是:
val main = Project("Mp3Streamer", file("."))
.enablePlugins(PlayScala)
.disablePlugins(PlayLayoutPlugin)
.settings(
target := baseDirectory.value / "target",
sourceDirectory in Compile := baseDirectory.value / "app",
// My change
sourceDirectory in Test := baseDirectory.value / "test" / "scala",
resourceDirectory in Compile := baseDirectory.value / "conf",
scalaSource in Compile := baseDirectory.value / "app",
// My change
scalaSource in Test := baseDirectory.value / "test" / "scala",
// I've added this resource
resourceDirectory in Test := baseDirectory.value / "test" / "resources",
javaSource in Compile := baseDirectory.value / "app",
sourceDirectories in(Compile, TwirlKeys.compileTemplates) := Seq((sourceDirectory in Compile).value),
sourceDirectories in(Test, TwirlKeys.compileTemplates) := Seq((sourceDirectory in Test).value),
// sbt-web
sourceDirectory in Assets := (sourceDirectory in Compile).value / "assets",
sourceDirectory in TestAssets := (sourceDirectory in Test).value / "assets",
resourceDirectory in Assets := baseDirectory.value / "public",
// Native packager
sourceDirectory in Universal := baseDirectory.value / "dist",
// Everything else is the same as the original Build.scala file
老实说,这感觉太老套了,我可能最终会修改我的目录结构以匹配 Play 的默认设置...但重要的是原则!