This message was deleted.
# community-support
s
This message was deleted.
v
i tried this - subprojects *{*Project project -> println "\njacoco configuring for sub project: " + name; if (name == 'abcProject') { Project subProject -> println "\nConfiguring jacoco reports for project: " + name; jacocoTestReport*{* getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec")) reports { xml.required = true html.required = true csv.required = false } } } }
i am seeing the outer `println "\njacoco configuring for sub project: " + name;`in output, but i am NOT seeing the inner
println "\nConfiguring jacoco reports for project: " + name;
in output
v
Actually, you should not do it at all.
subprojects { ... }
is highly disouraged as it adds project coupling and thus works against more sophisticated Gradle features and optimizations, besides that it makes builds less readable and less maintainable. Instead you should use convention plugins - for example implemented as precompiled script plugins - to have the common logic and then apply those convention plugins directly in the projects where their effect should be present.
Besides that, the
{ Project subProject ->
looks fishy. I think you test the
if
condition and if it is true define a closure that is just not used. If you remove the
Project subProject ->
, you probably get the result you intended
v
agreed...
{ Project subProject ->
is fishy.. removed it and things work as expected
@Vampire - could you help me understand why the earlier code was not working - is my below understanding correct. subprojects *{*Project project -> closure } and if (name == 'abcProject') { Project subProject -> not a closure but a code block } //but there are no compilation error. why so
v
As I said,
*{* Project subProject *-> not a closure but a code block* }
is a closure, not a code block. So
if (name == 'abcProject') *{* Project subProject *-> not a closure but a code block* }
is like when you do
if (name == 'abcProject') "foo"
. If the condition holds, the statement is evaluated. In the latter the statement is just defining a String literal. In the former, the statement is just defining a closure instance. But neither version does any more work than that.
v
you said: "`subprojects { ... }` is highly disouraged as it adds project coupling and thus works against more sophisticated Gradle features and optimizations, besides that it makes builds less readable and less maintainable." could you point any doc/example/tutorial/existing code of this.. so i can pickup on this concept
v
What is "this"?
v
i am referring to the suggestion you gave earlier.. plz see the first reply from you on this thread.
v
Maybe implemented as precompiled script plugins: https://docs.gradle.org/current/userguide/custom_plugins.html