Hello, Narco.
I'm a little confused as to what you are trying to do. I think maybe you
are using afterEvaluate unnecessarily, and that is confusing things. Maybe
try this:
subprojects {
usePlugin('java')
task compileUnitTests(type: Compile, dependsOn:compile) {
println "TODO: configure the unit tests compilation..."
}
task testUnitTests(type: Test, dependsOn: compileUnitTests) {
println "TODO: configure the unit tests..."
}
}
in place of the afterEvaluate closure. Even this seems a bit excessive,
however, as the java plugin provides built in 'testCompile' and 'test' tasks
that would do what you want (although you might need to configure the
convention if your project is not Maven-like in layout).
As for the "compileUnitTests is already run in definition phase" comment,
you are correct, it is! What you have there are "configuration" closures
that are run when the project is being defined, so they run immediately. If
you want an "execution" closure that only runs when the task is executed,
you need to use
task compileUnitTests(type: Compile, dependsOn:compile) << {
task ->
println task.project.name + " TODO: configure the unit tests
compilation..."
}
Note those two little "<<" symbols before the first {. That makes it an
execution closure. I'm not sure that's what you should use, however, as the
typical way to use "typed tasks" (type: Compile or type: Test) is to
configure them via a configuration closure. If you want to do extra work
before or after the built in processing of those special task types,
however, I would suggest
task compileUnitTests(type: Compile, dependsOn:compile) {
// configure the task here...
}
compileUnitTests.doFirst {
println 'before compiling unit tests'
}
compileUnitTests.doLast {
println 'after compiling unit tests'
}
These last two closures are execution closures (the '<<' is an alias for
doLast, so you wouldn't use it here). I hope this helps to make things more
clear. I think Gradle makes simple things easy and complex things possible,
but I agree it takes a bit of learning first!
--
John Murph
Automated Logic Research Team