String (@NotNull GradleProject subProject, @NotNull String rootProjectPath) { try { GradleScript script = subProject.getBuildScript(); if (script != null) { File file = script.getSourceFile(); if (file != null) { if (!file.isDirectory()) { // The file points to 'build.gradle' at the moment but we keep it's parent dir path instead. file = file.getParentFile(); } return ExternalSystemApiUtil.toCanonicalPath(file.getPath()); } } } catch (Exception e) { // As said by gradle team: 'One thing I'm interested in is whether you have any thoughts about how the tooling API should // deal with missing details from the model - for example, when asking for details about the build scripts when using // a version of Gradle that does not supply that information. Currently, you'll get a `UnsupportedOperationException` // when you call the `getBuildScript()` method'. // // So, just ignore it and assume that the user didn't define any custom build file name. } File rootProjectParent = new File(rootProjectPath); StringBuilder buffer = new StringBuilder(FileUtil.toCanonicalPath(rootProjectParent.getAbsolutePath())); Stack<String> stack = new Stack<>(); for (GradleProject p = subProject; p != null; p = p.getParent()) { stack.push(p.getName()); } // pop root project stack.pop(); while (!stack.isEmpty()) { buffer.append(ExternalSystemConstants.PATH_SEPARATOR).append(stack.pop()); } return buffer.toString(); }