How to output the source directory in sourceSet into a separate directory, or how to compile multiple sourceSets at the same time?


I now use gradle to manage my project, but use vscode-java to compile the project. The principle of vscode-java to compile the project is:
1. vscode-java calls buildship to initialize the project and synchronize the configuration information of the project.
2. Call to indirectly call the ECJ compiler.

Differences appear (gradle compile VS eclipse compile):

1. The sourceSets defined in gradle will be synchronized to the classpathentry element of .classpath. Here multiple sourceSets are converted into multiple classpathentry. Each classpathentry has a separate output directory. E.g: <classpathentry output="bin/a" kind="src" path="a/src">
2. Before compiling, javabuilder will translate each classpathentry into a SourceFile with an independent output directory. All SourceFiles are passed as parameters to the ECJ compiler.


Eclipse will treat all sourceSets as the same project and compile them at the same time; however, gradle’s sourceSets all correspond to a compilation task (which may have dependencies) and cannot be compiled at the same time.


Each source directory in sourceSets may have interdependencies, and each source directory needs to be compiled into a different independent output directory. E.g:

sourceSets {
    a {
        java {
            srcDirs = [a/src]
    b {
        java {
            srcDirs = [b/src]


----- a
----- b

I don’t really get what the question is. Each source set is compiled to a separate output directory by Gradle.

1 Like

First of all thank you very much for your reply. You are right.
But one difference is that sourceSet a and sourceSet b need to depend on each other and compile together. Finally output to a different independent directory.

I don’t think that is possible.
It is more a strong sign of code smell.
You should probably refactor your architecture to clean that up, or have them in the same source set.