Change Java home path

How could I change the Java home path of a project while I import it into Eclipse?

What is the API call when I know the absolute path to the Java home directory?

Or is it not possible at the moment?

I can change it manually in the project properties but I want to change it with an API while I import the project.

I found a way but the API is not really public (all referenced Buildship classes are of discouraged access):

ConfigurationManager manager = CorePlugin.configurationManager();
BuildConfiguration currentConfig = manager.loadProjectConfiguration(project);
BuildConfiguration updatedConfig = manager.createBuildConfiguration(...);

Is there another way by using public API?

Check out org.eclipse.buildship.core.GradleCore.getWorkspace().