[GRADLE-2678] Gradle may resolve project module dependencies wrongly Created: 12/Feb/13  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.0, 1.1, 1.2, 1.3, 1.4
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 0


I have a project with a structure like this

(and 100+ other modules)

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


{ 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?

Comment by Gradle Forums [ 12/Feb/13 ]

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

Comment by Gradle Forums [ 12/Feb/13 ]

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

Comment by Gradle Forums [ 12/Feb/13 ]

The forum doesn't support attachments. Best use an external service like [Gist]([1]https://gist.github.com/) or GitHub and post the link here.
[1] https://gist.github.com/

Comment by Gradle Forums [ 12/Feb/13 ]

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

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

Comment by Gradle Forums [ 12/Feb/13 ]

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.

Comment by Gradle Forums [ 12/Feb/13 ]

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]([1]http://gradle.org/docs/current/dsl/in...).)
  • Use different values for `project.group` for the consuming and producing projects, or don't set `project.group` at all.
    [1] http://gradle.org/docs/current/dsl/index.html
Comment by Peter Niederwieser [ 12/Feb/13 ]

Here is what I found. When resolving a project dep, Gradle internally represents both the consuming and the producing project as a module (version), where the module's name is the project's name, and the module's group is the parent project's path (roughly speaking). However, once project.group is set, that is used for the module's group. If consuming and producing projects additionally have the same name, the same module version will be used for both of them, leading to troubles.

To reproduce:


include 'util', 'workbench:util'
// uncommenting next line solves the problem
// project(":util").name = "foo"


allprojects {
  group = "foo" // not setting a group, or setting different groups, solves the problem
  apply plugin: "java" 


    compile project(":util")

task debug << {
  configurations.compile.each { println it }

Run gradle debug from the top level and observe that the compile configuration contains the util/workbench Jar, not the util Jar. Tested with Gradle 1.0-1.4.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:28:29 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.