On 11 May 2011 22:00, Adam Murdoch <[email protected]> wrote:

>
> On 11/05/2011, at 11:14 PM, Leo Mekenkamp wrote:
>
> Hi all,
>
> Is there a reason why there is no distinction between the separator between
> two project names and the separator between a project name and a task name?
> They both are ":".
>
> Reason I ask is because of the example in
> http://www.gradle.org/tutorial_using_tasks.html:
>
>
> gradle.taskGraph.whenReady {taskGraph ->
>     if (taskGraph.hasTask(':release')) {
>         version = '1.0'
>     } else {
>         version = '1.0-SNAPSHOT'
>     }
> }
>
> This example does not function properly when used in in a sub project. For
> sub projects one needs to (for instance) prepend getPath() like this:
>
>
> gradle.taskGraph.whenReady {taskGraph ->
>     if (taskGraph.hasTask(getPath() + ':release')) {
>         version = '1.0'
>     } else {
>         version = '1.0-SNAPSHOT'
>     }
> }
>
> Unfortunately, this would mean that you cannot simply use this example in
> an allprojects { } block, because getPath() returns ":" for the root
> project, and there is never a task "::release", only a task ":release".
>
>
> In allprojects { }, getPath() should be returning the path of the current
> project. Is this not the case?
>

Yes, it does, but for the root project getPath() + ':release') returns '
::release'

As an alternative, you can pass in a task object into hasTask(), so you
> don't need to worry about paths and names. For example:
>
> allprojects {
>     gradle.taskGraph.whenReady { graph ->
>         if (graph.hasTask(release)) { ... } else { ... }
>     }
> }
>

That is even better.

Cheers,
--L

Reply via email to