Skip to content

Commit

Permalink
Gradle: fix IllegalStateException when resolving project deps
Browse files Browse the repository at this point in the history
Fixes a regression from #37938
  • Loading branch information
snazy committed Feb 7, 2024
1 parent 607afed commit 0b11b30
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ public static Project findIncludedProject(Project project, ExternalModuleDepende
}
}

final Gradle parentGradle = project.getRootProject().getGradle().getParent();
if (parentGradle != null) {
return findIncludedProject(parentGradle.getRootProject(), dependency);
} else {
try {
final Gradle parentGradle = project.getRootProject().getGradle().getParent();
if (parentGradle != null) {
return findIncludedProject(parentGradle.getRootProject(), dependency);
} else {
return null;
}
} catch (IllegalStateException ise) {
// This can happen if the project itself is in an included build, which means that the root-project
// is not yet known, so `DefaultGradle.getRootProject()` throws an ISE.
return null;
}
}
Expand All @@ -134,9 +140,15 @@ private static Project findIncludedBuildProject(IncludedBuild ib, ExternalModule
}

final DefaultIncludedBuild.IncludedBuildImpl dib = (DefaultIncludedBuild.IncludedBuildImpl) ib;
final Project rootProject = dib.getTarget().getMutableModel().getRootProject();
try {
final Project rootProject = dib.getTarget().getMutableModel().getRootProject();

return findLocalProject(rootProject, dependency);
return findLocalProject(rootProject, dependency);
} catch (IllegalStateException ise) {
// This can happen if the project itself is in an included build, which means that the root-project
// is not yet known, so `DefaultGradle.getRootProject()` throws an ISE.
return null;
}
}

public static Path serializeAppModel(ApplicationModel appModel, Task context, boolean test) throws IOException {
Expand Down

0 comments on commit 0b11b30

Please sign in to comment.