Depend on Multiproject build


(Conall Prendergast) #1

Hi,
Is it possible to have a “compile project” dependency on a multiproject build.
For example, I have:

root
  A (depends on B)
  B-parent
    B-api
    B-impl
    settings.gradle
    build.gradle
  settings.gradle
  build.gradle

The project B structure above was imported from maven during the “gradle init” task.
The problem is when I run a “gradle dependencies” in A it does not include “B-api” or “B-impl”.
Am I doing something wrong here with my nested muliproject configurations?


(Conall Prendergast) #2

Ok, so I think I dont fully understand the best practices regarding multi project builds.

Suppose I have developed a custom logging library that alot of my projects depend on. Lets call it “myLogger”, and the dependee “myApp”.
Would I consider myLogger to be a subproject of myApp?
If so, would it be in a subdirectory of all the dependee modules?
Would I nest it like the following?

myApp
    |-myLogger
       | - build.gradle
       | - src
    |-myOtherSharedLibraries
    |-settings.gradle

myApp2
   | - myLogger <- ????

What if myLogger is in fact a multi project build, would it change to the following?

myApp
    |-myLogger
        | - api
        | - settings.gradle
        | - build.gradle
    |-myOtherSharedLibraries
    |-settings.gradle

I suppose I just dont know when to make something a multi-project build and when to keep them seperate.
Thanks for the help and sorry for the really noobish question.


(Stefan Oehme) #3

A multi-project build needs to list all of its subprojects in settings.gradle. There are no “nested multi-projects”.

What you are looking for is called a composite build (a build including another build), which will be a new feature in Gradle 3.1.

Now as for the myLogger project: That should not be in the same repository as your app, since myLogger is used by other apps as well, right? Instead, myLogger should be in its own repository and app should have a binary dependency on it.

With composite build you will then be able to combine the myLogger and app builds into one composite, so you can e.g. test a bugfix in myLogger against app without first having to publish a new version of myLogger.

Cheers,
Stefan


(Conall Prendergast) #4

Hi Stefan
myLogger is indeed in its own repo. But what I was doing up until now was having a project dependency on it (and many other projects having a project dependency on it), which I now think might be the wrong thing to do. I was thinking either composite builds or a maven install (to mavenLocal) was a better way to do this.

So to clarify, a multi-project build is only used for a one-to-one relationship?
Many thanks,
Conall


(Stefan Oehme) #5

Exactly, multi project builds are for things that are developed, versioned
and released together.


(Conall Prendergast) #6

Thanks for explaining that Stefan