I am fighting with a fairly simple gradle problem but despite searching I cannot find a solution. Very simple, in a multi project build, I need configure some subproject based on the plugins they load. So If sub project has plugin 'war' or 'ear' do this.. I have tried the following without success:
subprojects {
if (it.plugins.hasPlugin('war') || (it.plugins.hasPlugin('ear') {
apply plugin: 'my super special plugin'
....
....
}
}
The above never apply plugin: 'my super special plugin'
Any suggestion? Thanks
Gradle executes
subprojects
closure before evaluating build.gradle from subprojects. Therefore, there are no information about plugins frombuild.gradle
at this point. To execute some code after evaluation of thesubproject/build.gradle
you should use ProjectEvaluationListener. For example:Also note about
it.plugins.apply 'my super special plugin'
instead ofapply plugin: 'my super special plugin'
Another option is to use shared
common.gradle
wich will configure subprojects. This shared gradle file may be included in thesubproject/build.gradle
by usingapply from: '../common.gradle'
in proper place.