Related question: is it okay to configure multiple...
# community-support
s
Related question: is it okay to configure multiple projects to share the same projectDir? The reason I'm asking is that I have a legacy build that I want to refactor and it separates projects kind of logically rather than physically. There's a common directory with roughly 10 modules, and 5 of them belong to project A and the rest to project B. I would like to create two separate Gradle build files in the common directory, project-a.gradle.kts and project-b.gradle.kts, and specify this directory as projectDir for both. Is this supported? How can I give them different buildDirs early enough in that case?
Looks like IntelliJ IDEA is not okay with this setup so I probably won't go there.
e
in principle projects can use sources outside of the project directory, e.g.
Copy code
sourcesets {
  main {
    java.srcDir("../src/main/java")
    resources.srcDir("../src/main/resources")
  }
}
but overlapping source sets confuse the IDE too so you shouldn't do that from multiple projects
y
Related question: is it okay to configure multiple projects to share the same projectDir?
In short, yes, but you'll need to do some additional work. In `settings.gradle`:
Copy code
include 'proj-a'
project(':proj-a').projectDir = 'common-dir'
include 'proj-b'
project(':proj-b').projectDir = 'common-dir'
In
common-dir/build.gradle
Copy code
buildDir = "${projectDir}/build-${project.name}"
OR
Copy code
project.layout.buildDirectory.value("${projectDir}/build-${project.name}")
s
Thanks, yes, I was considering also specifying separate build files in settings.gradle but I’ve abandoned the whole idea anyway.