Composite Builds and Flavors

So Gradle has this awesome feature called ‘Composite Builds’. I can include a project in my project and replace a maven dependency with a real project.

includeBuild('/path/to/project') {
        dependencySubstitution {
            substitute module("com.example:somelib") with project(':somelib')

This works but not if the included project has product flavors. In such case gradle doesn’t know how to choose the configuration to build the project and throws up with the following error:

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve com.example:somelib:1.2.0
     Required by:
         project :app > project :data > project :sdk
      > The consumer was configured to find an API of a component, as well as attribute '' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :SomeLib:somelib>]>
          - devDebugAndroidTestCompile
          - devDebugAndroidTestRuntime
          - devDebugApiElements
          - devDebugRuntime
          - devDebugRuntimeElements
          - devDebugUnitTestCompile
          - devDebugUnitTestRuntime
          - devReleaseRuntime
          - devReleaseUnitTestCompile
          - devReleaseUnitTestRuntime
          - prodDebugAndroidTestCompile
          - prodDebugAndroidTestRuntime
          - prodDebugApiElements
          - prodDebugRuntime
          - prodDebugRuntimeElements
          - prodDebugUnitTestCompile
          - prodDebugUnitTestRuntime
          - prodReleaseRuntime
          - prodReleaseUnitTestCompile
          - prodReleaseUnitTestRuntime
        All of them match the consumer attributes:

If I get rid of product flavors everything works fine.

Still looking for the solution.