Manual execution of build task

855 views
Skip to first unread message

eugene.m...@gmail.com

unread,
Jan 27, 2014, 12:56:13 PM1/27/14
to adt...@googlegroups.com
Hi,

I have a task that needs to do some work before calling build itself. And I wanted to call build manually from that task. Accordingly to what I have found it can be done with something like this:

task someTask << {
    ...
    tasks['build'].execute()
    ...
}

But it does not trigger build at all. Though the same way of calling tasks works fine with the tasks declared inside build.gradle.
Am I missing something here?

P.S. I was able to trigger build by placing dependsOn inside task declaration
task someTask(dependsOn : 'build') << {
...
}

but it is not what I am looking for

Xavier Ducrohet

unread,
Jan 27, 2014, 1:20:26 PM1/27/14
to adt...@googlegroups.com
There's a task called "preBuild" that is run before all other tasks, so you could do the following:

task someTask << {
}
preBuild.dependsOn someTask

This ensures that your task is always run before a build.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Anton Rutkevich

unread,
Jan 27, 2014, 1:22:35 PM1/27/14
to adt...@googlegroups.com
Hi, 

I may be missing something, but as far as I remember, executing tasks with execute() method executes only task itself, not its task dependencies.
Besides, execute() is internal api of org.gradle.api.internal.AbstractTask

Luke Daley

unread,
Jan 29, 2014, 2:51:28 PM1/29/14
to adt...@googlegroups.com
Yes, calling execute() on tasks is not supported in any way.

Gradle is always in control of deciding when to execute tasks (i.e. via dependsOn, mustRunAfter, finalizedBy etc.) and not the build script author. Therefore, it makes no sense to try and programatically execute a task.
> --
> You received this message because you are subscribed to the Google Groups "adt-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Luke Daley
Principal Engineer, Gradleware
http://gradleware.com

eugene.m...@gmail.com

unread,
Jan 30, 2014, 12:50:52 PM1/30/14
to adt...@googlegroups.com
Now I see. Thanks for your answers.
Reply all
Reply to author
Forward
0 new messages