Hello, I’m pretty new to both gradle and groovy. I’ve got a bit of trouble of accessing a configuration defined in one project from another project. I’ve got it working in the end but the solution is very confusing to me and I’m not sure if I’m really doing the right thing there. So here’s my question.
The Problem -----------------
I’ve got a very simple multi-project structure just like below:
Root project ‘gradle_test’
±-- Project ‘:sub1’
-– Project ‘:sub2’
This is what the ‘build.grade’ file looks like for sub1 project:
// build.gradle of sub1 project
task testConfiguration {
println project(‘:sub2’).configurations.sub2FooConfiguration
}
And finally, this is the ‘build.grade’ file of sub2 project:
// build.gradle of sub2 project
configurations {
sub2FooConfiguration
}
Very minimum. Now, if I run ‘gradle :sub1:testConfiguration’, I got the following error:
A problem occurred evaluating project ‘:sub1’.
Could not find property ‘sub2FooConfiguration’ on configuration container.
However, everything just works if the ‘testConfiguration’ task in sub1 project is modified like this:
// notice the “<<” (I believe this is calling the ‘doLast’ method on the task instance)
task testConfiguration << {
println project(‘:sub2’).configurations.sub2FooConfiguration
}
The Question -------------------
What I assume the difference between the two versions of the ‘testConfiguration’ task is that in the first instance, a ‘configuration closure’ is passed to the task whereas in the modified version a ‘normal’ closure is passed to the ‘doLast’ method.
So, first of all, is my assumption correct?
Secondly, why I don’t have access to ‘sub2’ project in the first instance?
And finally, is it possible to access ‘sub2’ project in the first instance (i.e. in the configuration closure)?