How gradle merge different aar versions of different lib in Android?

I have two library, which depends on the same aar, in first library, I use this:

compile 'this.is.the.aar:library:0.0.1'

but second library, I use:

compile 'this.is.the.aar:library:0.0.2'

the 0.0.1 and 0.0.2 have totally different api, if I change the version in the first library to 0.0.2, it will get compilation error. The dependency tree is like this:

myproject
|-library 1
  |-aar:0.0.1
|-library 2
  |-aar:0.0.2

When I write this, the compilation can pass, and run OK. I just wonder why this works, how the gradle merge the arrs.