I have managed to solve my use-case but it is a bit tricky and it calls internal API. Here is the solution:
@SuppressWarnings("restriction")
public static IMavenExecutionContext createExecutionContext(final IMavenProjectFacade facade,
final IProgressMonitor monitor) throws CoreException {
return MavenPluginActivator.getDefault().getMavenProjectManagerImpl()
.createExecutionContext(facade.getPom(), facade.getResolverConfiguration());
}
public static <V> V executeInContext(final IMavenProjectFacade facade,
final Consumer<MavenExecutionRequest> executionRequestModifier,
final ICallable<V> callable, final IProgressMonitor monitor) throws CoreException {
IMavenExecutionContext executionContext = createExecutionContext(facade, monitor);
MavenExecutionRequest executionRequest = executionContext.getExecutionRequest();
return executionContext.execute((context, monitor1) -> {
if (executionRequestModifier != null) {
executionRequestModifier.accept(executionRequest);
}
return MavenPlugin.getMaven().createExecutionContext()
.execute(facade.getMavenProject(monitor), callable, monitor);
}, monitor);
}