I have in buildSrc - multiProject build,so I want to apply to all of the subprojects ‘codeNarc’ plugin and to configure it. So in the build.gradle file in the buildSrc, I wrote
But Only codenarc is applyed. The other configurations are not applied, even the println doesn’t work and with 1 violation the build fails? Where is my fault?
the problem with your snippet is, that it your configuration block is only applied to the CodeNarc tasks that are already in the tasks container and will not affect CodeNarc tasks added later on (e.g. when the java plugin is applied). The culprit is this line:
tasks.withType(CodeNarc).each { codeNarcTask ->
To fix this behaviour, you should not use the .each method. instead gradle offers you to apply this logic lazily for all tasks in that container and all matching tasks added somewhen in the future by using this syntax instead:
in project.afterEvaluate block this(old version with each) doesn’t work. And I am wondering why? In afterEvaluate I have CodeNarc tasks in tasks container, or I am wrong?