class CompilerClassloaderUtils {

    public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath,
                                                                          String localRepo,
                                                                          String settingsXmlPath) {

        AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH));
        WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath)));
        CompilationRequest req;
        if (settingsXmlPath != null) {
            req = new DefaultCompilationRequest(localRepo,
                                                info,
                                                new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath},
                                                Boolean.FALSE);
        } else {
            req = new DefaultCompilationRequest(localRepo,
                                                info,
                                                new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH},
                                                Boolean.FALSE);
        }
        CompilationResponse res = compiler.compile(req);
        if (res.isSuccessful()) {
            /** Maven dependency plugin is not able to append the modules classpath using an absolute path in -Dmdep.outputFile,
             it override each time and at the end only the last writted is present in  the file,
             for this reason we use a relative path and then we read each file present in each module to build a unique classpath file
             * */
            if (!res.getDependencies().isEmpty()) {
                Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies());
                if (urlClassLoader.isPresent()) {
                    return urlClassLoader;
                }
            }
        }
        return Optional.empty();
    }

    private  CompilerClassloaderUtils();

}