/documentation/en/2.0/manual/detailledTopics/build/SBTSettings.md

https://github.com/opensas/playdoces · Markdown · 111 lines · 65 code · 46 blank · 0 comment · 0 complexity · e9d1596ed5d62d36389ed433e0bdf200 MD5 · raw file

  1. # About SBT Settings
  2. ## About sbt settings
  3. The sbt build script defines settings for your project. You can also define you own custom settings for your project, as described in the [[sbt documentation | https://github.com/harrah/xsbt/wiki]].
  4. To set a basic setting, use the `:=` operator:
  5. ```scala
  6. val main = PlayProject(appName, appVersion, appDependencies).settings(
  7. confDirectory := "myConfFolder"
  8. )
  9. ```
  10. ## Default settings for Java applications
  11. Play 2.0 defines a default set of settings suitable for Java-based applications. To enable them add the `defaultJavaSettings` set of settings to your application definition:
  12. ```scala
  13. val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA)
  14. ```
  15. These default settings mostly define the default imports for generated templates. For example, it imports `java.lang.*`, so types like `Long` are the Java ones by default instead of the Scala ones. It also imports `java.util.*` so the default collection library will be the Java one.
  16. ## Default settings for Scala applications
  17. Play 2.0 defines a default set of settings suitable for Scala-based applications. To enable them add the `defaultScalaSettings` set of settings to your application definition:
  18. ```scala
  19. val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA)
  20. ```
  21. These default settings define the default imports for generated templates (such as internationalized messages, and core APIs).
  22. ## Play project settings with their default value
  23. When you define your sbt project using `PlayProject` instead of `Project`, you will get a default set of settings. Here is the default configuration:
  24. ```scala
  25. resolvers ++= Seq(
  26. "Maven Repository" at "http://repo1.maven.org/maven2/",
  27. "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
  28. ),
  29. target <<= baseDirectory / "target",
  30. sourceDirectory in Compile <<= baseDirectory / "app",
  31. confDirectory <<= baseDirectory / "conf",
  32. scalaSource in Compile <<= baseDirectory / "app",
  33. javaSource in Compile <<= baseDirectory / "app",
  34. distDirectory <<= baseDirectory / "dist",
  35. libraryDependencies += "play" %% "play" % play.core.PlayVersion.current,
  36. sourceGenerators in Compile <+= (confDirectory, sourceManaged in Compile) map RouteFiles,
  37. sourceGenerators in Compile <+= (sourceDirectory in Compile, sourceManaged in Compile, templatesTypes, templatesImport) map ScalaTemplates,
  38. commands ++= Seq(
  39. playCommand, playRunCommand, playStartCommand, playHelpCommand, h2Command, classpathCommand, licenseCommand, computeDependenciesCommand
  40. ),
  41. shellPrompt := playPrompt,
  42. copyResources in Compile <<= (copyResources in Compile, playCopyResources) map { (r, pr) => r ++ pr },
  43. mainClass in (Compile, run) := Some(classOf[play.core.server.NettyServer].getName),
  44. compile in (Compile) <<= PostCompile,
  45. dist <<= distTask,
  46. computeDependencies <<= computeDependenciesTask,
  47. playCopyResources <<= playCopyResourcesTask,
  48. playCompileEverything <<= playCompileEverythingTask,
  49. playPackageEverything <<= playPackageEverythingTask,
  50. playReload <<= playReloadTask,
  51. playStage <<= playStageTask,
  52. cleanFiles <+= distDirectory.identity,
  53. resourceGenerators in Compile <+= LessCompiler,
  54. resourceGenerators in Compile <+= CoffeescriptCompiler,
  55. resourceGenerators in Compile <+= JavascriptCompiler,
  56. playResourceDirectories := Seq.empty[File],
  57. playResourceDirectories <+= baseDirectory / "conf",
  58. playResourceDirectories <+= baseDirectory / "public",
  59. templatesImport := Seq("play.api.templates._", "play.api.templates.PlayMagic._"),
  60. templatesTypes := {
  61. case "html" => ("play.api.templates.Html", "play.api.templates.HtmlFormat")
  62. case "txt" => ("play.api.templates.Txt", "play.api.templates.TxtFormat")
  63. case "xml" => ("play.api.templates.Xml", "play.api.templates.XmlFormat")
  64. }
  65. ```