File (@Nullable Project project) { Ref<File> ref = myCachedGradleHomeFromPath; if (ref != null) { return ref.get(); } String path = System.getenv("PATH"); if (path == null) { return null; } for (String pathEntry : path.split(File.pathSeparator)) { File dir = new File(pathEntry); if (!dir.isDirectory()) { continue; } for (String fileName : GRADLE_START_FILE_NAMES) { File startFile = new File(dir, fileName); if (startFile.isFile()) { File candidate = dir.getParentFile(); if (isGradleSdkHome(project, candidate)) { myCachedGradleHomeFromPath = new Ref<>(candidate); return candidate; } } } } return null; }