How to define arbitrary tasks in the Play Framework? (like ruby rake)

后端 未结 2 672
清酒与你
清酒与你 2021-01-12 04:44

How to define arbitrary tasks in the Play Framework?

I mean tasks run from the command line, something similar to ruby rake.

I\'m aware of the ant tool but l

2条回答
  •  灰色年华
    2021-01-12 05:15

    For Play 2, you can create new tasks using SBT, by following the documentation here:

    http://www.scala-sbt.org/release/docs/Detailed-Topics/Tasks

    In the context of a Play 2 generated Build.scala, it might look like this:

    import sbt._
    import Keys._
    import play.Project._
    
    object ApplicationBuild extends Build { 
    
      val appName         = "foo"
      val appVersion      = "1.0-SNAPSHOT"
    
      val appDependencies = Seq(
        // Add your project dependencies here,
        jdbc,
        anorm
      )
    
      val hello = TaskKey[Unit]("hello", "Prints 'Hello World'")
    
      val helloTask = hello := {
        println("Hello World")
      }
    
      lazy val main = play.Project(appName, appVersion, appDependencies).settings(
        helloTask
      )
    }
    

提交回复
热议问题