Build multi flavors project

Hallo! i have a problem about building project.
I try write android application with Flavors. But i can’t found resolution for my problem.
My problem is
i have project with java code, this project have dependencies with another models for example like this
dependencies {
implementation(’:A’)
implementation(’:B’)
}

this project have 2 productFlavors
productFlavors {
flavor1 {}
flavor2 {}
}

next my “flavor1” have binary dependencies with module B
its look like this

dependencies {
flavor1Implementation(name:‘B’,ext:‘aar’)
}

but on this case i have conflict in project…

dependencies {
implementation(’:A’)
implementation(’:B’) <-- conflict
flavor1Implementation(name:‘B’,ext:‘aar’)<-- conflict
}

my question is - How can i say to gradle “if current flavor is flavor1 use aar files - if flavor2 use module dependencies” ?
example diogram like this
diogramm
sorry about my English :blush: