"Weak" dependencies in a multi-project setup

I have a simple multi-project setup. Project A is an Android client and Project B is a Tomcat-based backend that the Android client accesses. These two projects do not share any code. The Project A requires the Android plugin. Now here is the problem: when you cd into Project B (Tomcat) and run “gradle build”, gradle apparently includes Project A to compute the task graph (because it is referenced in settings.gradle). The unfortunate thing is that this requires a developer for Project B also to configure the Android SDK required by Project A.

There is a “weak” dependency here: Projects A and B are both needed for the final product (and hence there should be a top-level build-mechanism). But a developer for Project B does not want to be concerned with SDKs needed for the other project.

How can this be done?

If Project B can “stand alone”, you can simply tell Gradle not to search upwards for a settings.gradle file using the -u command line option, effectively removing it from the multi-project.

Thanks for your response. I tried to keep the scenario simple, but there is actually a Project C (some common code) that both A and B depend on. When I wrote in my original post “A and B do not share code”, I should have written “A does not depend on B and vice versa”. The -u option would prevent B to pick up C. Sorry for not mentioning that in my original post.

No worries. In that case you could still conditionally exclude Project B in your settings.gradle based on a system property or something similar.

if (System.getProperty('excludeAndroid') == null) {
    include ':projectB'
}

Then you can just set the system prop on the command line like ./gradlew -DexcludeAndroid build

Very clever! That’ll do it! Thanks!

You might also want to try and see if --configure-on-demand results in the desired outcome. It should avoid having to evaluate the Project B build script unless you are building that project (or a project that depends on it).