0

I'm struggling with Gradle and the build configuration of the following project structure (pretty simple...):

/projA
   /projB
   /projC

projC using classes from projB.

In projA/settings.gradle:

include 'projB'
include 'projC'

In projC/build.gradle:

dependencies{
 compile project(':projB')
}

In IntelliJ I have no problem of dependency resolution, but when I'm running a ./gradlew build in projA, I'm facing a compilation error:

ClassC: Unresolved reference: ClassB

(where ClassC is the class of projC which is failing on the use of ClassB which is a class from projB, obviously...)

Notice that the code is in Kotlin language, that I do not have any problem to run the app in IntelliJ (spring boot run), but any build with Gradle give me an error (both in Intellij and command line).

What am I missing?

Regards, Adrien

AdZaf
  • 127
  • 8

1 Answers1

0

It's a common Gradle idiom to have an additional top level directory for your rootProject. That's a special project that's the parent to all other projects in your build, in a multi-project build.

That's where your settings.gradle file goes:

include ':projA:projB'
include ':projA:projC'

Then, I'd recommend having projA as a subdirectory of your rootProject, so your hierarchy would look as follows:

/myProject
  settings.gradle
  /projA
    build.gradle
    /projB
      build.gradle
    /projC
      build.gradle

Also, in projC/build.gradle, you'll want instead:

dependencies {
  compile project(':projA:projB')
}

That should do it.

Felipe Lima
  • 10,530
  • 4
  • 41
  • 39
  • Thanks Felipe, staying with my first project hierarchy (projA as parent of projB and projC), `compile project(":projB")` in build.gradle on my projC won't do the job? why do I need to add an additional top level since projA is already a toplevel project acting as parent project? – AdZaf May 04 '18 at 19:28
  • AFAIK Gradle will want you to provide the "full path" to your project dependencies, that's why you need `":projA:projB"`, think of it as a relative path to a directory. – Felipe Lima May 04 '18 at 19:53