Search code examples
javaintellij-ideagradlebuild-dependencies

Gradle Transitive Dependencies from Modules


Disclaimer: I'm new to Gradle, have read a lot of docs, and I don't know whether my maven-style understanding is tripping me out, or whether it's the sleep dep (kids - don't ask), but I'm still not getting it.

Problem Background:
I have a project that consists of several modules.
One of the modules, let's call it data-structure defines a data structure
Another module, data-structure-fabsearch, defines an implementation for a data source for the data structure, and finally
A third module, fabsearch-common, defines some common data source classes (eg: connection management to a fabsearch data source etc).

The reason I've done it like this is because there's actually another module that also uses the fabsearch-common stuff.

Anyway, my data-structure-fabsearch build.gradle looks something like this:

dependencies {
   compile project(:data-structure)
   compile project(:fabsearch-common)
}

The fabsearch-common module declares depedencies for the fabsearch api (let's call it fabsearch-api-1.0.0).

So, the dependency tree for data-structure-fabsearch should look like this:

- data-structure-fabsearch
   - data-structure
   - fabsearch-common
     - fabsearch-api-1.0.0

This was all working wonderfully last night. This morning I came to work and all of a sudden those dependencies don't resolve anymore. References to fabsearch-api-1.0.0 classes are no longer found.

What I've Tried
1. In the parent build.gradle:

project(':data-structure-fabsearch'){
    apply plugin: 'java'
    dependencies {
        compile project(path: ':data-structure', configuration: 'compile')
        compile project(path: ':fabsearch-common', configuration: 'compile')
    }
}

I've tried this with and without the configuration setting.
2. In the data-structure-fabsearch build.gradle file, adding the configuration parameter.
3. Restarting IntelliJ
4. Clicking the refresh icon in the Gradle tool window (repeatedly)
5. Reading all about transitive dependencies in the Gradle user guides
6. Drinking tea (repeatedly)

None of the above work.

What I'm Expecting
I'm expecting that the fabsearch-common dependencies (the fabsearch-api jars) should also be included in the data-structure-fabsearch dependency tree. All references to fabsearch-api classes in data-structure-fabsearch should resolve etc etc.

My Question[s]
Whilst this is possible in Maven, is it possible in Gradle?
What do I have to do to get it to work?
How much sleep dep can you take without dying?

Many thanks for any help.


Solution

  • Turns out the problem wasn't gradle at all. The problem was IntelliJ.

    It got it's knickers into a proper twist!

    Solution:
    1. Close the project in IntelliJ
    2. Delete the .idea directory
    3. Delete all .iml files and any other IntelliJ cra-useful files
    4. Open project in IntelliJ, choose same directory. Problem disappears.