我正在使用sbt [0.13]使用scala [2.10.3]编译play [2.2]项目。我有用于数据库迁移的.sql文件和scala文件。目录结构如下所示:
app
|-> db
|-> migration
|-> V1__init.scala
|-> V2__newTable.sql
当我从播放控制台(REPL)运行编译时,scala文件(V1__init.scala)被编译为.class并复制到classes文件夹。但是.sql文件没有被移动。
我尝试添加unmanagedResourceDirectories in Compile <++= baseDirectory { dir => Seq(dir/"app/db/migration") ++ Seq(dir/"db/migration") }
,但它没有复制文件。整个块看起来像:
val main = play.Project(appName, appVersion, appDependencies).settings(
scalaVersion := "2.10.3",
scalacOptions ++= Seq("-feature"), // enable feature warnings
unmanagedResourceDirectories in Compile <++= baseDirectory { dir => Seq(dir/"app/db/migration") ++ Seq(dir/"db/migration") }
)
我也尝试使用copyResources
,但无法使用它。这里描述:http://www.playframework.com/documentation/2.0/SBTSettings
那么有谁知道如何将sql文件复制到classes文件夹中?
谢谢!
更新
我有IO.copyDirectory(new java.io.File("app/db/migration"), new java.io.File("target/scala-2.10/classes/db/migration"), true)
来复制文件,但目的地是硬编码的,并且会在我更新scala时更改
答案 0 :(得分:0)
val main = play.Project(appName, appVersion, appDependencies).settings(
scalaVersion := "2.10.3",
scalacOptions ++= Seq("-feature"), // enable feature warnings
unmanagedResourceDirectories in Compile <+= scalaSource in Compile,
excludeFilter in unmanagedResources in Compile := "*.scala" || "*.java"
)
您可以使用以下命令轻松检查类文件夹中的内容:
sbt clean full-classpath && ls target/scala-2.10/classes/db/migration/