Gradle-model-core dependency for Gradle 5.6.3

I am trying to upgrade my project from gradle 4.10.3 to 5.6.3 and one of the groovy classes (i.e. custom plugin) in the project uses ClassGenerator from org.gradle.api.internal package.

When I first tried to build with gradle 5.6.3, I got the error saying unable to resolve class org.gradle.api.internal.ClassGenerator. I then looked into the github repo and found that the class has moved into model-core subproject and now resides under org.gradle.api.internal.instantiation package. So, I changed the import statement to:

import org.gradle.api.internal.instantiation.ClassGenerartor

However, I still get the error unable to resolve class org.gradle.api.internal.instantiation.ClassGenerator. I already have compileOnly gradleApi() in dependencies. Do I need to do anything else to use this class?

To provide a bit more info, I am using ClassGenerator to create instances of the classes. In 5.6.3, this interface has been made package private (that might be why I am getting the above error). Below is the code where ClassGenerator is used:

instance = classGenerator.newInstance(Class, rootProject).with{..}

How can I do the same with gradle 5.6.3? Do I need to use other API/Class?