Gradle fails to detect flat dependency

(sergey.morenets) #1

I have a multi-project Gradle build (Gradle 4.4).
And I encountered the following issue.

Let’s say I have proj1 project with the following build.gradle:

repositories {
   flatDir {
       dirs 'libs'

dependencies {
       compile name: 'lombok-edge'

proj1 has libs folder with lombok-edge.jar. Project is built successfully.
And I have proj2 that imports proj1:

dependencies {
	compile project(':proj1')

When I try to build the whole project proj1 is build but Gradle fails to build proj2 with an error:

  • What went wrong:
    Could not resolve all files for configuration ‘:proj2:compileClasspath’.

Could not find :lombok-edge:.
Required by:
project :proj2 > project :proj1

Please advise.

(Chris Doré) #2

When a dependency on proj1 is declared in proj2, proj1 brings along its declared dependencies, not its resolved dependency artifacts. The resulting dependency tree is then resolved in the context of proj2. If proj2 does not define a repository that can also resolve proj1’s dependencies, then dependency resolution fails.

(sergey.morenets) #3

Thank you, @Chris_Dore

So how can I fix this issue?

(Chris Doré) #4

If you share the flat repository between both projects by declaring it in both projects, then the dependencies should resolve.

For example, if the libs directory was in the root project directory, then you could define the repository in the same manner in both proj1 and proj2 as:

repositories {
    flatDir {
        dir rootProject.file( 'libs' )

(sergey.morenets) #5

Thank you, that fixes this issue. But I have two concerns.

The biggest concern is that there are also proj3, proj4 and other projects that depend on proj1. So this solution looks not very scalable.

Another concern is that I have to insert this repositories block in the projects that don’t use this lombok-edge dependency. That looks weird to me. Why shoud I have to declare dependency in the build script if I don’t use it?

(guai) #6

maybe you just need to make lombok dependency compileOnly so it would not be inherited by other projects depending on proj1 via trasitive dependencies
didn’t try it though