Q:

Android gradle build: running assembleDebug makes release tasks of project dependencies being called

When running assembleDebug, the release related tasks of projects I depend on are called.
e.g.
I have a project called 'x' which depends on 'y'.
When I gradle assembleDebug it calls y:mergeReleaseProguardFiles, packageReleaseAidl, etc... etc..

A:

Edit: Not true anymore, with Android Gradle Plugin 3.x.
The libraries also publish debug and release artifacts. If the project has flavors or custom types, those are also created. And across modules, it tries to automatically match variants. If not matched, you need to provide matchingFallback to match variants across modules. More info can be found here: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#resolve_matching_errors

Android library modules publishes only "release" build type. They don't have "debug" build type. Even your application module build the debug version, it will use the release version of the library. 
You can enable "debug" build type of the library dependency using the following in your module's build.gradle file:
android {
  publishNonDefault true
  ...
}

Then when you are using that dependency in the other module, you should use like this:
dependencies {
  releaseCompile project(path: ':moduleY', configuration: 'release')
  debugCompile project(path: ':moduleY', configuration: 'debug')
}

I am using the same trick in my application. I have a shared module and I use debug version of the module. Find details here: 
https://github.com/pomopomo/WearPomodoro/blob/develop/mobile/build.gradle#L90

