DaemonParameters (BuildLayoutParameters layout) { try { Factory<PatternSet> patternSetFactory = PatternSets.getPatternSetFactory(PatternSpecFactory.INSTANCE); //noinspection JavaReflectionMemberAccess IdentityFileResolver identityFileResolver = IdentityFileResolver.class.getConstructor(Factory.class).newInstance(patternSetFactory); //noinspection JavaReflectionMemberAccess Constructor<DefaultFileCollectionFactory> collectionFactoryConstructor = DefaultFileCollectionFactory.class.getConstructor( PathToFileResolver.class, TaskDependencyFactory.class, DirectoryFileTreeFactory.class, Factory.class); DefaultFileCollectionFactory factory = collectionFactoryConstructor.newInstance( identityFileResolver, DefaultTaskDependencyFactory.withNoAssociatedProject(), new DefaultDirectoryFileTreeFactory(), patternSetFactory); //noinspection JavaReflectionMemberAccess return DaemonParameters.class.getConstructor(BuildLayoutParameters.class, FileCollectionFactory.class).newInstance(layout, factory); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Cannot create DaemonParameters by reflection, gradle version " + GradleVersion.current(), e); } }