Dependency on task in Model-based plugin (Play) not working


I’m trying to create a task dependency on on a task from the Play Framework plugin. The reason I’m doing it is because I’d like to use Launch4j to create an exe.

I’m using the launch4j plugin (id ‘’ version ‘1.6.1’), and I want one of its tasks to depend on the Play plugin’s stagePlayBinaryDist task (as well as rely on the task for a listing of output files).

I keep getting ‘task does not exist’ sort of errors when I do:
copyL4jLib.dependsOn project.tasks.getByName('stagePlayBinaryDist')

However, if I do:
gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph -> println project.tasks.getByName('stagePlayBinaryDist') }
it works fine, which makes me think that the tasks are being dynamically added or something.

Is there something I’m missing here? How would I be able to set
copyL4jLib.dependsOn project.tasks.getByName('stagePlayBinaryDist') launch4j { mainClassName = 'play.core.server.NettyServer' copyConfigurable = project.tasks.getByName('stagePlayBinaryDist') }


The problem is that the Play support is built on the new software model and the model rules are evaluated after everything else in the script. The Play tasks are set up in model rules, so trying to set up the dependency in “classic” gradle space won’t work unless you defer the evaluation until after the model rules fire. One option is to use a string or a closure instead of a direct object reference:

copyL4jLib.dependsOn "stagePlayBinaryDist"
copyL4jLib.dependsOn { stagePlayBinaryDist }

A more robust solution would be to declare the dependency as a rule in the model block - something like:

model {
    tasks {
        copyL4jLib {
            dependsOn $.tasks.stagePlayBinaryDist

Okay, that makes sense to me, I just wasn’t sure how to go about it.
Thanks for the help!