Hi Narco,
On Jul 21, 2009, at 5:11 PM, Narco wrote:
Hello!
I see You have a lot of changes did from 0.5.2 version. I have a bit
time
for Gradle investigation, upgraded to new 7.0 and my simple scripts
are not
working anymore. Few things I discovered by myself but there is
problem with
addAfterEvaluateListener. It seems that on 0.7 it should be the same
afterEvaluate so there is my code from master build.gradle:
subprojects {
afterEvaluate { Project subproject ->
task compileUnitTests (type: Compile, dependsOn: compile){
println subproject.getName() + " TODO: configure the unit tests
compilation..."
}
}
}
All I need is to create new task for every subproject.
On multi-project build it runs once for "app" module and then gives:
Cause: Cannot add task ':web-main:compileUnitTests' as a task with
that name
already exists.
BUILD FAILED
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
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email