Multi-module project with relative paths to sub projects


(tulsoba) #1

I have the following projects (flat structure):

trunk
 -> A
  -> B
 -> C-War

where C contains the main deliverable/war file. I would like A and B to be subprojects for C. Unfortunately I cannot change the structure, eg. nest A and B inside C. So what I am trying to do it this:

trunk
 -> A
   -> src
   -> build.gradle
 -> B
   -> src
   -> build.gradle
 -> C-War
   -> src
   -> webapp
   -> build.gradle
   -> settings.gradle

where the settings.gradle contains:

include "../A", "../B"
//include "A", "B"

So I need C-War to be the root folder for the ‘parent’ build.gradle file and the ‘parent’ settings.gradle file. These files cannot be located in the root of trunk.

But the above fails/the subprojects cannot be found, even though I specify relative paths to the subprojects.

Is it somehow possible to achieve the above?


(detelinyordanov) #2

The Settings.include method accepts a Gradle project path - this is different than a filesystem path - it uses the ‘’:’’ character as a path separator. With this method you are building the Gradle project hierarchy, while if the actual filesystem hierarchy is different than that, then you must use ProjectDescriptor.projectDir to set the actual directory for each project:

include ':A'
project(':A').projectDir = new File('../A')
include ':B'
project(':B').projectDir = new File('../B')

(nm2501) #3

Another option you might consider is the use of symlinks from within C, pointing to A and B. In my plugins I create symlinks automatically using java.nio.file.Files.createSymbolicLink().