IDEA-163185 [Gradle|Sync] fix: don't resolve the content root as a build root for the generated sources under it

The build root cannot be excluded and used as a content root at the same time.

GitOrigin-RevId: 9129066a84a51db569b1058e27a92db49c6624ef
This commit is contained in:
Sergei Vorobyov
2024-09-02 16:52:10 +02:00
committed by intellij-monorepo-bot
parent 7818039983
commit 3ca055a407

View File

@@ -59,21 +59,25 @@ class GradleContentRootIndex {
): Set<Path> {
val projectRootPath = externalProject.projectDir.toPath()
val buildRootPath = externalProject.buildDir.toPath()
val contentRootPaths = NioPathPrefixTreeFactory.createSet()
for (sourceDirectorySet in sources.values) {
for (sourceRootPath in sourceDirectorySet) {
val contentRootPath = resolveContentRoot(projectRootPath, sourceRootPath)
val contentRootPath = resolveContentRoot(projectRootPath, buildRootPath, sourceRootPath)
contentRootPaths.add(contentRootPath)
}
}
return contentRootPaths.getRoots()
}
private fun resolveContentRoot(projectRootPath: Path, sourceRootPath: Path): Path {
private fun resolveContentRoot(projectRootPath: Path, buildRootPath: Path, sourceRootPath: Path): Path {
if (!sourceRootPath.startsWith(projectRootPath)) {
return sourceRootPath
}
if (sourceRootPath.startsWith(buildRootPath)) {
return sourceRootPath
}
val contentRootPath = sourceRootPath.parent
if (contentRootPath == null || contentRootPath == projectRootPath) {
return sourceRootPath