hdockter wrote:
>
> Hi Narco,
>
> It is no problem to solve this. Yet it is a bit of a tricky one.
>
> Some Groovy background: A closure always has an owner and a delegate.
>
> When you do:
>
> subprojects {
> <someStatement>
> }
>
> Gradle iterates over all subprojects. <someStatement> is first applied
> against the delegate (which is the subproject). If the subproject does
> not have a property or method used in <someStatement>, the statement
> is applied against the root project.
>
> When you do:
>
> subprojects {
> afterEvaluate { Project subproject ->
> task ...
> }
> }
>
> The afterEvaluate closure is a nested closure. Therefore the above
> mechanism does not work. You have to explicitly define which project
> you want to add the task to:
>
> subprojects {
> afterEvaluate { Project subproject ->
> subproject.task ...
> }
> }
>
> But this will also fail (for a different reason). The problem is that
> our DSL magic does not work inside the nested closure. You have to use
> the plain Java API:
>
> subprojects {
> afterEvaluate { Project subproject ->
> subproject.tasks.add('compileUnitTests')) {...}
> }
> }
>
> Sorry that this is so complicated. We should think how to make this
> work better.
>
> - Hans
>
> --
> Hans Dockter
> Gradle Project Manager
> http://www.gradle.org
>
Hello Hans!
Now I`m having another problem. This behaviour works fine when I have one
subproject.
afterEvaluate { Project subproject ->
subproject.usePlugin('java')
subproject.tasks.add(name:'compileUnitTests', type: Compile,
dependsOn: compile){
println subproject.getName() + " TODO: configure the
unit tests compilation..."
}
subproject.tasks.add(name:'testUnitTests', type: Test,
dependsOn: compileUnitTests){
println subproject.getName() + "TODO: configure unit
tests..."
}
}
When I have added 2nd project in settings.gradle which does not differ from
1st project I get build failed:
gradle -C=off testUnitTests
app TODO: configure the unit tests compilation...
Build failed with an exception.
Run with -s or -d option to get more details. Run with -f option to get the
full
(very verbose) stacktrace.
Build file
'C:\work\perf\SCM\Build\Ant\Project\Release_2_0_1\MDL\build.gradle' l
ine: 64
Failed to notify action.
Cause: Could not find property 'compileUnitTests' on project
':ejb-module-sessio
n'.
BUILD FAILED
Also what looks wrong to me is that task 1stProj:compileUnitTests is already
run in definition phase. Although 1stProj:testUnitTests is not run. But
cause is shown as compileUnitTests task is not found in 2nd project which
shouldn`t be started to define before 1st project at all.
I don`t understand gradle at all. Even simple things are so difficult...
--
View this message in context:
http://www.nabble.com/addAfterEvaluateListener--%3E-afterEvaluate---tp24589609p25352445.html
Sent from the gradle-user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email