1

I would like to run a task in farm task:

farm {
   // run my task here.
}

Can anyone help me with this?

Opal
  • 81,889
  • 28
  • 189
  • 210
Le Kim Trang
  • 369
  • 2
  • 5
  • 17
  • 1
    Could you be please more precise about what you need to do? As far as I see _farm_ is an _extension_ and tasks are not designed to be run inside extensions. – Opal Feb 24 '16 at 09:14
  • I would like to call ./gradlew farmRun , and it will automatically run one of my task or function. Thanks a lot. – Le Kim Trang Feb 24 '16 at 09:18
  • Then define a dependency between your task and `farmRun` task. – Opal Feb 24 '16 at 09:52
  • Dear Opal, can you show me exactly the way, I have no clue. Thanks a lot. – Le Kim Trang Feb 24 '16 at 09:56

1 Answers1

3

farm is an extension - not a task - so it cannot be run. Also mind the fact that it's not good idea, nor good practice to run task programmatically. You need to define your own task and then define a dependency:

task myTask << {
   println "Here's an action"
}

farmRun.dependsOn myTask

or:

task myTask << {
   println "Here's an action"
}

project.afterEvaluate {
   farmRun.dependsOn myTask
}

Please have a look at the demo here.

Opal
  • 81,889
  • 28
  • 189
  • 210
  • Hi, I got error with farmRun.dependsOn Could not find property 'farmRun' on project ':bl-notification-server'. and replace it to farm.dependsOn myTask, after that another error occurs: A problem occurred evaluating project ':bl-notification-server'. > Could not find method dependsOn() for arguments [task ':bl-notification-server:myTask']. Please advise, thanks a lot. – Le Kim Trang Feb 24 '16 at 10:21
  • Hi Opal, it's no error now when I run: ./gradlew farmRun, but I cannot see the line: Here's an action. – Le Kim Trang Feb 24 '16 at 10:58
  • @LeKimTrang, added the demo to prove that it works well. – Opal Feb 24 '16 at 19:11
  • Dear Opal, thank you very much. It's really help. How's about gradle deamon? Can we treat gradle deamon as task? Thank you very much. – Le Kim Trang Feb 25 '16 at 07:14