0


In a multi-project build I have a module that in itself is composed of two sub-projects. If I just want the option of building the top-level module but also ensure both the sub-projects within it are also built, how I do achieve this?

include 'moduleA', 'moduleB', 'moduleC' (root project settings.gradle)
project(':moduleC').projectDir = new File('path to custom module that includes sub-projects)
project(':moduleC').settingsDir = ?? (gradle fails because there is no settingsDir path)

but moduleC has a settings.gradle in itself that has

include 'api'
include 'server'

Now I want both these to be triggered when I specify gradlew :moduleC:build, but instead it just builds moduleC root project. Is there a way? This use case does seem valid to me (i.e. for modularity, you want to keep the inclusion of sub-projects at moduleC's level and not at root level).

Thanks,
Paddy

Paddy
  • 3,472
  • 5
  • 29
  • 48

1 Answers1

1

As of Gradle 2.2, only a single settings.gradle per build is supported. If that file contains include "moduleC:api" and include "moduleC:server", then running gradle build from moduleC's project directory will also build api and server.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • Hi @Peter, what will gradlew :moduleC:build do if I try it from root project directory? Will it still build both api and server or will tha happen only if I run gradle from moduleC's project directory? – Paddy Nov 28 '14 at 09:55
  • No, it will just run the `build` task in `moduleC` (or error out if there isn't any). Of course, you can always declare your own task that `dependsOn ":moduleC:api:build"` and `dependsOn ":moduleC:server:build"`. – Peter Niederwieser Nov 28 '14 at 09:57
  • Is it like tasks[':moduleC:build'].dependsOn(':moduleC:api:build') for example? – Paddy Nov 28 '14 at 09:59
  • Depending on your exact motivations/needs, you might do something like `task buildAll { dependsOn build, ":moduleC:api:build", ":moduleC:server:build" }` in `moduleC/build.gradle`. – Peter Niederwieser Nov 28 '14 at 10:39
  • Here's a technique I used to get around this limitation: http://stackoverflow.com/a/29664571/204480 – James Wald Apr 16 '15 at 03:02