Groovy syntax question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Groovy syntax question

Roman Shaposhnik-2
Hi!

while working with Gradle I've come across a behavior
that I find impossible to explain. Basically, how is it possible
for 'exec' in the first line to resolve and the one in println
line not to?

I'd really appreciate if somebody can explain what the first
exec resolves to and why:

$ cat build.gradle
exec {
  commandLine "echo", "foo"
}

println exec

$ gradle -q
foo

FAILURE: Build failed with an exception.

* Where:
Build file '/private/tmp/P/build.gradle' line: 5

* What went wrong:
A problem occurred evaluating root project 'P'.
> Could not find property 'exec' on root project 'P'.

Thanks,
Roman.
Reply | Threaded
Open this post in threaded view
|

Re: Groovy syntax question

Thibault Kruse
In a gradle file, all methods and properties are resolved against a
project instance. so the first exec really is project.exec({...}), and
the second exec is println(project.exec). You can type it like that in
gradle as well, giving you somewhat better IDE support.

Also there is a gradle forum for gradle related questions, which may
be better than this mailing list for this kind of question.
Reply | Threaded
Open this post in threaded view
|

Re: Groovy syntax question

Jochen Theodorou
In reply to this post by Roman Shaposhnik-2
On 02.07.2016 09:06, Roman Shaposhnik wrote:
[...]
> I'd really appreciate if somebody can explain what the first
> exec resolves to and why:
>
> $ cat build.gradle
> exec {
>    commandLine "echo", "foo"
> }

this is a method call to exec.

> println exec

this is asking for the property exec. Method calls without arguments
must be done as exec() in Groovy. Furthermore properties and methods are
mostly separate. So it is very possible the exec method exists and the
property does not.

bye Jochen

Reply | Threaded
Open this post in threaded view
|

Re: Groovy syntax question

Roman Shaposhnik-2
Thibault, Jochen,

thank you guys -- you got me going (turns out my confusion was partially
because newly defined tasks are also visible as a property).

One final question -- do you have any recommendation on how to
debug (well, trace actually) Groovy scripts inside of Gradle build.gradle?

Seems like my go-to IDE InteliJ is broken in that regard. Any suggestions
on what may work?

Thanks,
Roman.

On Sat, Jul 2, 2016 at 1:26 AM, Jochen Theodorou <[hidden email]> wrote:

> On 02.07.2016 09:06, Roman Shaposhnik wrote:
> [...]
>>
>> I'd really appreciate if somebody can explain what the first
>> exec resolves to and why:
>>
>> $ cat build.gradle
>> exec {
>>    commandLine "echo", "foo"
>> }
>
>
> this is a method call to exec.
>
>> println exec
>
>
> this is asking for the property exec. Method calls without arguments must be
> done as exec() in Groovy. Furthermore properties and methods are mostly
> separate. So it is very possible the exec method exists and the property
> does not.
>
> bye Jochen
>
Reply | Threaded
Open this post in threaded view
|

Re: Groovy syntax question

Thibault Kruse
I have no advice beyond what can be found via google.

On Sun, Jul 3, 2016 at 8:56 AM, Roman Shaposhnik <[hidden email]> wrote:

> Thibault, Jochen,
>
> thank you guys -- you got me going (turns out my confusion was partially
> because newly defined tasks are also visible as a property).
>
> One final question -- do you have any recommendation on how to
> debug (well, trace actually) Groovy scripts inside of Gradle build.gradle?
>
> Seems like my go-to IDE InteliJ is broken in that regard. Any suggestions
> on what may work?
>
> Thanks,
> Roman.
>
> On Sat, Jul 2, 2016 at 1:26 AM, Jochen Theodorou <[hidden email]> wrote:
>> On 02.07.2016 09:06, Roman Shaposhnik wrote:
>> [...]
>>>
>>> I'd really appreciate if somebody can explain what the first
>>> exec resolves to and why:
>>>
>>> $ cat build.gradle
>>> exec {
>>>    commandLine "echo", "foo"
>>> }
>>
>>
>> this is a method call to exec.
>>
>>> println exec
>>
>>
>> this is asking for the property exec. Method calls without arguments must be
>> done as exec() in Groovy. Furthermore properties and methods are mostly
>> separate. So it is very possible the exec method exists and the property
>> does not.
>>
>> bye Jochen
>>
Reply | Threaded
Open this post in threaded view
|

Re: Groovy syntax question

Jochen Theodorou


On 05.07.2016 10:03, Thibault Kruse wrote:

> I have no advice beyond what can be found via google.
>
> On Sun, Jul 3, 2016 at 8:56 AM, Roman Shaposhnik <[hidden email]> wrote:
>> Thibault, Jochen,
>>
>> thank you guys -- you got me going (turns out my confusion was partially
>> because newly defined tasks are also visible as a property).
>>
>> One final question -- do you have any recommendation on how to
>> debug (well, trace actually) Groovy scripts inside of Gradle build.gradle?
>>
>> Seems like my go-to IDE InteliJ is broken in that regard. Any suggestions
>> on what may work?

for a normal script you can set a break point in your ide and it will
stop there. But for gradle you  would have to start gradle itself with
debugging.. so for example something like

export GRADLE_OPTS="-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

and then start your gradle, with breakpoint set.

and if everything fails, println is your friend ;)

bye Jochen