DaemonParameters (BuildLayoutParameters layout) { try { ClassLoader classLoader = DaemonAction.class.getClassLoader(); // Using reflection for code: "new BuildLayoutConverter$Result(BuildLayoutParameters);" Class resultClass = classLoader.loadClass("org.gradle.launcher.cli.converter.BuildLayoutConverter$Result"); Constructor resultConstructor = resultClass.getConstructor(layout.getClass()); resultConstructor.setAccessible(true); BuildLayoutResult buildLayoutResult = (BuildLayoutResult)resultConstructor.newInstance(layout); resultConstructor.setAccessible(false); Factory<PatternSet> patternSetFactory = PatternSets.getPatternSetFactory(PatternSpecFactory.INSTANCE); //noinspection JavaReflectionMemberAccess IdentityFileResolver identityFileResolver = IdentityFileResolver.class.getConstructor().newInstance(); DefaultFileCollectionFactory collectionFactory = createCollectionFactory6Dot3(identityFileResolver, patternSetFactory); return DaemonParameters.class.getConstructor(BuildLayoutResult.class, FileCollectionFactory.class).newInstance(buildLayoutResult, collectionFactory); } catch (ClassNotFoundException | NoSuchFieldException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Cannot create DaemonParameters by reflection, gradle version " + GradleVersion.current(), e); } }