PageRenderTime 103ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/iwawiwi/play20
Markdown | 168 lines | 100 code | 68 blank | 0 comment | 0 complexity | 99a22fe73f921c95a1ead043a0c512ed 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 your own custom settings for your project, as described in the [sbt documentation](http://www.scala-sbt.org). In particular, it helps to be familiar with the [settings](http://www.scala-sbt.org/release/docs/Getting-Started/More-About-Settings) in sbt.
  4. To set a basic setting, use the `:=` operator:
  5. ```scala
  6. val main = play.Project(appName, appVersion, appDependencies).settings(
  7. confDirectory := "myConfFolder"
  8. )
  9. ```
  10. ## Default settings for Java applications
  11. Play 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 = play.Project(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 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 = play.Project(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 `play.Project` instead of `Project`, you will get a default set of settings. Here is the default configuration:
  24. ```scala
  25. resolvers ++= Seq(
  26. "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/",
  27. "Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/"
  28. ),
  29. target <<= baseDirectory / "target",
  30. sourceDirectory in Compile <<= baseDirectory / "app",
  31. sourceDirectory in Test <<= baseDirectory / "test",
  32. confDirectory <<= baseDirectory / "conf",
  33. resourceDirectory in Compile <<= baseDirectory / "conf",
  34. scalaSource in Compile <<= baseDirectory / "app",
  35. scalaSource in Test <<= baseDirectory / "test",
  36. javaSource in Compile <<= baseDirectory / "app",
  37. javaSource in Test <<= baseDirectory / "test",
  38. distDirectory <<= baseDirectory / "dist",
  39. libraryDependencies += "play" %% "play" % play.core.PlayVersion.current,
  40. libraryDependencies += "play" %% "play-test" % play.core.PlayVersion.current % "test",
  41. parallelExecution in Test := false,
  42. testOptions in Test += Tests.Setup { loader =>
  43. loader.loadClass("play.api.Logger").getMethod("init", classOf[java.io.File]).invoke(null, new java.io.File("."))
  44. },
  45. testOptions in Test += Tests.Cleanup { loader =>
  46. loader.loadClass("play.api.Logger").getMethod("shutdown").invoke(null)
  47. },
  48. testOptions in Test += Tests.Argument("sequential", "true"),
  49. testOptions in Test += Tests.Argument("junitxml", "console"),
  50. testListeners <<= (target, streams).map((t, s) => Seq(new eu.henkelmann.sbt.JUnitXmlTestsListener(t.getAbsolutePath, s.log))),
  51. testResultReporter <<= testResultReporterTask,
  52. testResultReporterReset <<= testResultReporterResetTask,
  53. sourceGenerators in Compile <+= (confDirectory, sourceManaged in Compile, routesImport) map RouteFiles,
  54. // Adds config/routes to continious triggers
  55. watchSources <+= confDirectory map { _ / "routes" },
  56. sourceGenerators in Compile <+= (sourceDirectory in Compile, sourceManaged in Compile, templatesTypes, templatesImport) map ScalaTemplates,
  57. // Adds views template to continious triggers
  58. watchSources <++= baseDirectory map { path => ((path / "app") ** "*.scala.*").get },
  59. commands ++= Seq(shCommand, playCommand, playRunCommand, playStartCommand, h2Command, classpathCommand, licenseCommand, computeDependenciesCommand),
  60. shellPrompt := playPrompt,
  61. copyResources in Compile <<= (copyResources in Compile, playCopyAssets) map { (r, pr) => r ++ pr },
  62. mainClass in (Compile, run) := Some(classOf[play.core.server.NettyServer].getName),
  63. compile in (Compile) <<= PostCompile,
  64. dist <<= distTask,
  65. computeDependencies <<= computeDependenciesTask,
  66. playVersion := play.core.PlayVersion.current,
  67. playCommonClassloader <<= playCommonClassloaderTask,
  68. playCopyAssets <<= playCopyAssetsTask,
  69. playCompileEverything <<= playCompileEverythingTask,
  70. playPackageEverything <<= playPackageEverythingTask,
  71. playReload <<= playReloadTask,
  72. playStage <<= playStageTask,
  73. cleanFiles <+= distDirectory,
  74. ebeanEnabled := false,
  75. logManager <<= extraLoggers(PlayLogManager.default),
  76. ivyLoggingLevel := UpdateLogging.DownloadOnly,
  77. routesImport := Seq.empty[String],
  78. playIntellij <<= playIntellijTask,
  79. playHash <<= playHashTask,
  80. // Assets
  81. playAssetsDirectories := Seq.empty[File],
  82. playAssetsDirectories <+= baseDirectory / "public",
  83. resourceGenerators in Compile <+= LessCompiler,
  84. resourceGenerators in Compile <+= CoffeescriptCompiler,
  85. resourceGenerators in Compile <+= JavascriptCompiler,
  86. lessEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.less") --- base / "assets" ** "_*")),
  87. coffeescriptEntryPoints <<= (sourceDirectory in Compile)(base => base / "assets" ** "*.coffee"),
  88. javascriptEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" ** "*.js") --- (base / "assets" ** "_*"))),
  89. lessOptions := Seq.empty[String],
  90. coffeescriptOptions := Seq.empty[String],
  91. closureCompilerOptions := Seq.empty[String],
  92. // Templates
  93. templatesImport := Seq("play.api.templates._", "play.api.templates.PlayMagic._"),
  94. templatesTypes := {
  95. case "html" => ("play.api.templates.Html", "play.api.templates.HtmlFormat")
  96. case "txt" => ("play.api.templates.Txt", "play.api.templates.TxtFormat")
  97. case "xml" => ("play.api.templates.Xml", "play.api.templates.XmlFormat")
  98. })
  99. ```
  100. > **Next:** [[Managing library dependencies | SBTDependencies]]