File (Project project, CppBinary cppBinary) { Throwable throwable = null; try { if (cppBinary instanceof ConfigurableComponentWithExecutable) { PlatformToolProvider toolProvider = ((ConfigurableComponentWithExecutable)cppBinary).getPlatformToolProvider(); ToolSearchResult toolSearchResult; if (IS_410_OR_BETTER) { toolSearchResult = toolProvider.locateTool(ToolType.CPP_COMPILER); } else { Method isToolAvailableMethod = toolProvider.getClass().getDeclaredMethod("isToolAvailable", ToolType.class); isToolAvailableMethod.setAccessible(true); toolSearchResult = (ToolSearchResult)isToolAvailableMethod.invoke(toolProvider, ToolType.CPP_COMPILER); } if (toolSearchResult.isAvailable()) { if (toolSearchResult instanceof CommandLineToolSearchResult) { return ((CommandLineToolSearchResult)toolSearchResult).getTool(); } // dirty hack for gradle versions <= 4.9 because of dummy implementation of org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppPlatformToolProvider.isToolAvailable if (toolProvider.getClass().getSimpleName().equals("VisualCppPlatformToolProvider")) { Field visualCppField = toolProvider.getClass().getDeclaredField("visualCpp"); visualCppField.setAccessible(true); Object visualCpp = visualCppField.get(toolProvider); if (visualCpp instanceof NativeLanguageTools) { return ((NativeLanguageTools)visualCpp).getCompilerExecutable(); } } } } } catch (Throwable t) { throwable = t; } NativeToolChain toolChain = cppBinary.getToolChain(); String exeName; if (toolChain instanceof Gcc) { exeName = "g++"; } else if (toolChain instanceof Clang) { exeName = "clang++"; } else if (toolChain instanceof VisualCpp) { exeName = "cl"; } else { exeName = null; } if (exeName != null) { ToolSearchPath toolSearchPath = new ToolSearchPath(OperatingSystem.current()); CommandLineToolSearchResult searchResult = toolSearchPath.locate(ToolType.CPP_COMPILER, exeName); if (searchResult.isAvailable()) { return searchResult.getTool(); } } if (!IS_47_OR_BETTER) { project.getLogger().error( "[sync error] Unable to resolve compiler executable. " + "The project uses '" + GradleVersion.current() + "' try to update the gradle version"); } else { project.getLogger().error("[sync error] Unable to resolve compiler executable", throwable); } return null; }