0

How can I exclude certain subprojects in my multi-project gradle build. I want to exclude a apply plugin call by querying a property of the subproject.

The build.gradle of my parent project looks like this:

subprojects {
    if (!ext.has('excludeProject')) {
        apply plugin: 'org.example.DemoPlugin'
    }
}

And the build.gradle of some subprobjects contain this:

ext {
    excludeProject = true
}

This does not work. The plugin is always applied. I also tried different syntax like if(!project.ext.exclude) or if(!project.hasProperty('exclude')).

What works is: if I put a "gradle.properties" in the subproject and define the property there (excludeProject=true), then it works.

If I query "if(project.name != "subproject")that also works, but I dont want that solution. Is there a way to get it working by using extension properties in the build.gradle ?

paddy3k
  • 149
  • 1
  • 11

1 Answers1

1

Placing the excludeProject in the buildscript { ext { ... } } appears to be applying the property too late for the subprojects { ... } to detect them.

You can place a line like this in your subprojects { ... } to reveal the properties available at that time:

println(ppp.ext.getProperties().keySet())

The project simply isn't evaluated enough yet for these to be populated if you do it this way. However, if you place excludeProject = true into a gradle.properties in your sub-module, it does detect it through what I tried (Gradle 8.0.1).

User51
  • 887
  • 8
  • 17
  • Thanks for your help, I also think that it is simply not possible that way. I will use the gradle.properties workaround until I find a better solution. – paddy3k Mar 01 '23 at 10:31