Why disabled transitive dependency is visible in the dependent module?

I have a question regarding transitive dependency. This question is best illustrated by the following simple example. Let’s say I have two java modules — “module1” and “module2”. The “module1” has compile dependency on some third party library:

dependencies {
  compile('commons-lang:commons-lang:2.6') {
    transitive = false
  }
}

Note, that I intentionally disabled transitive dependencies of this dependency (exactly as in the example from javadoc for DependencyHandler).

The “module2” has compile dependency on “module1”:

dependencies {
  compile project(':module1')
}

The classes in both modules use some utility class from “commons-lang” library. I was expecting that compilation of “module2” should fail since ‘commons-lang:commons-lang:2.6’ dependency marked as non-transitive in the “module1”. But both modules are compiled successfully. What I’m doing wrong? Or maybe I just misunderstand transitive dependencies concept. Could you comment, please?

The ‘transitive’ flag dates back to Gradle’s Ivy roots, and therefore works like Ivy’s own ‘transitive’ flag. Which is: Only the flag of the configuration that’s being resolved counts. You should be able to get the desired behavior with ‘compile(‘commons-lang:commons-lang:2.6@jar’)’.

Got it. However, it did not help. The second module still successfully compiled even if I use

dependencies {
  compile('commons-lang:commons-lang:2.6@jar') {
    transitive = false
  }
}

in the first module.

Sorry, I didn’t read your initial post carefully enough. With today’s Gradle, it’s expected that ‘commons-lang’ makes it on the compile class path of module2. ‘@jar’, and in fact also ‘transitive = false’, successfully prevent Gradle from fetching and propagating ‘commons-lang’'s dependencies, but they don’t affect ‘commons-lang’ itself.

Looks quite reasonable, though at first for me it was not obvious (perhaps brief clarification in the documentation would be quite useful)… Thank you very much for the explanation.