dependsOn broken? Bad form?


(Chad Walz) #1

My colleague developed an interesting little problem for gradle and I’m trying to explain it to him. I have done a search, and found some similar, I didn’t find something that solves the problem. Here it is:

caseTwo has three subprojects, alpha, bravo, and charlie

alpha depends on charlie

charlie depends on bravo

if your run gradle hello, you see the expected results:

gradle hello
 :bravo:hello
  Hello, I'm bravo
  :charlie:hello
  Hello, I'm charlie
  :alpha:hello
  Hello, I'm alpha

But, these projects also have a compile dependency

alpha has a compile dependency on charlie.jar

charlie has a compile dependency on bravo.jar

if you run gradle build, you get an error:

gradle build
 :bravo:compileJava UP-TO-DATE
  :charlie:compileJava UP-TO-DATE
  :alpha:compileJava
    FAILURE: Build failed with an exception.
    * What went wrong:
  Could not find group:extlibs,
   module:charlie, version:.
  Required by:
      caseTwo:alpha:unspecified

=========================

The caseThree jar is very similar, but uses alphabetic ordering

bravo dependsOn alpha

charlie dependsOn bravo

gradle hello shows the dependencies:

:alpha:hello

Hello, I’m alpha

:bravo:hello

Hello, I’m bravo

:charlie:hello

Hello, I’m charlie

gradle build runs to completion.

====================================

It looks to me like dependsOn is broken… maybe somewhere in the engine it resorts to alphabetic ordering… what do you think? Am I missing something? Is there a different way to do this?

Here’s the build.gradle file for case two:

subprojects {
    apply plugin: 'java'
    task hello << {Task task ->
        println "Hello, I'm $task.project.name"
    }
}

Here’s the build.gradle in alpha

repositories {
    flatDir name: 'extlibs', dirs: ["../charlie/build/libs"]
}
  dependencies {
    dependsOn(':charlie')
    compile 'extlibs:charlie'
}

Thanks in advance and let me know if I’m leaving something useful out.


(Chad Walz) #2

Really sorry about the formatting…I’m trying to clean it up.


(Peter Niederwieser) #3

Could you please fix the formatting? All code should go into code tags or be indented with four spaces (Markdown syntax).

Is it on purpose that you connect the projects in such an odd way (external dependency instead of project dependency, use of project.dependsOn(), use of project.dependsOn() with a dependencies {} block)?

A minimal but complete code example would make it easier to answer your question.


(Chad Walz) #4

Thanks, Peter. Is it possible to attach jars to explain? I think the problem is in the strange syntax that you mention, but it does work in case 3. Also, I’m not able to edit my post. I did edit once before by selecting edit in the upper right hand corner of my post, but it seems to have disappeared. The deleted message was me saying sorry for the bad formatting :stuck_out_tongue:

If it’s easier, please delete this post and I’ll try again. Thanks again, Peter.


(Peter Niederwieser) #5

Could you please try to refresh the page in your browser? Then the ‘edit’ button should appear again.


(Peter Niederwieser) #6

I’d prefer a self-contained example without attached Jars.


(Peter Niederwieser) #7

I think the problem is in the strange syntax that you mention, but it does work in case 3

If two tasks have no dependsOn relationship, Gradle is free to run them in any order. Currently it happens to use alphabetic order, but that’s an implementation detail and not a guaranteed behavior.


(Chad Walz) #8

I tried refreshing, deleting cache, clearing history, etc in chrome and still no luck with the edit button returning. Thanks again for your input, Peter.

How do I get caseTwo to not error on a build command? gradle --debug doesn’t seem to be of much help to me. What is the smarter syntax?


(Peter Niederwieser) #9

alpha/build.gradle should contain just this:

dependencies {

project(":charlie")

}

You can read more about project dependencies in the user guide.