Composite builds, Sharing multiple ouput directories for the dependent module

Consider the following setup :

configurations {
    codeGen
}

sourceSets {
    codeGen {
        java {
            srcDirs = [ "codeGen"]
        }
    }
}

sourceSets {
    main {
        java {
            srcDirs = ["src"]
        }
    }
}

As we understand, with above setup, compileJava and compileCodeGenJava will have its own output directories as below.

compileJava        ----> $buildDir/classes/java/main
compileCodeGenJava ----> $buildDir/classes/java/codeGen

Also, It is not possible for us to club the two compilation steps into one. With that assumption, Is it possible to share both output directories (main and codeGen) for the modules dependent on this module? By default, only $buildDir/classes/java/main will be used for the dependency substitution.

I have much simplified our use case here, but if we can get the possible options for above mentioned scenario, we will be more than happy. We tried giving the same destinationDir for both the JavaCompile tasks but it leads us to unexpected problems during rebuild (as in build on already built code with some minor code changes). Also, by doing so, we are not able to leverage from the build cache and incremental build like features.

Can you please comment on this @st_oehme ?

We have composite build with 180+ included builds with each build producing only one jar artifact. What is the recommendation for the above use case?

We tried sharing the output directories for both JavaCompile tasks viz. compileJava and
compileCodeGenJava and had issues wrt to build failures and also where not able to leverage UP-TO-DATE and FROM-CACHE like features .