Gradle falvors conflict

I have the following module dependency:
app {

module1 {

module 2 (no flavors)

now the app dependencies are as follows:

flavor1Complie project(path:  ':module1', configuration: ':flavor1')
flavor2Complie project(path:  ':module1', configuration: ':flavor2')
complie project(path:  ':module2')

and the module2 dependencies are as follows:

compile project(path: ':module1')

So now when i compile app with flavor2 i have an issue that module1 is compiled twice, once as flavor2 and once as the default flavor, flavor1 (module2 compiles it in the deafault flavor).

and so i get an error when building the app since i have the same packages twice.

Can someone help me to get this working. i need module1 to compile only once according to the flavor selected in app