Gradle may resolve project module dependencies wrongly


(Jesper Thuun-Petersen) #1

I have a project with a structure like this

/util /workbench/util (and 100+ other modules)

the workbench/util has a single dependency to the upper level util like this:

dependencies{
    compile project(":util")
}

When I build this module, however, the compilation fails, with errors indicating that the dependent module cannot be found.

The compiler arguments look like this:

  [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -d E:\code\trunk\stepx\workbench\util\build\classes\main -g -classpath E:\code\trunk\stepx\workbench\util\build\libs\util-1.0-SNAPSHOT.jar …  

Notice that the dependency to the util is resolved to the workbench/util module’s OWN artifact, instead of the upper level artifact!!

I have tried to invoke the command “gradle :util:assemble” when in the workbench/util sub-directory. It does build the root level util project, as should be suspected. I also generate IntelliJ Idea modules for the project. Here, the dependency is also OK.

Renaming one of the modules is not an option, as it is an existing project with 100+ live customers, and several live branches.

Is there a viable workaround for the time being, as I suspect the described behavior is a bug you will have to fix?


(Peter Niederwieser) #2

I cannot reproduce this. Can you provide a minimal reproducible example?


(Jesper Thuun-Petersen) #3

Hi Peter, I have created a very minimal example demonstrating the problem. Can I send you a zip file somehow through the forum?


(Peter Niederwieser) #4

The forum doesn’t support attachments. Best use an external service like Gist or GitHub and post the link here.


(Jesper Thuun-Petersen) #5

I have uploaded the example to my google drive. Please download the example here:

https://docs.google.com/file/d/0BxgX3GzSY7VFRldUTS1vUS1NZms/edit?usp=sharing


(Jesper Thuun-Petersen) #6

In my example, if you rename the upper level util project to ie utils, the code will compile. As it is now, the compilation fails.


(Peter Niederwieser) #7

Thanks for the example. This is indeed a bug. Some ways to work around:

  • Use different values for ‘project.name’ for the consuming and producing projects. Note that this doesn’t mean that you need to rename any directories. Project names and directories can be configured independently in ‘settings.gradle’. (See ‘Settings’ in the Gradle Build Language Reference.) * Use different values for ‘project.group’ for the consuming and producing projects, or don’t set ‘project.group’ at all.

(Jesper Thuun-Petersen) #8

Thanks for the hints. I now set the group name explicitly in my subproject build.gradle files. That seems to do the trick!