Hello Steve,
I am not sure I correctly understand what you are trying to achieve. Are you trying to move kotlin-gradle-plugin build to Gradle?
If you have your patch available on Github, I could try to download it and investigate.
There obviously is some difference in classpath between IntelliJIdea, Maven and Gradle. E.g., gradleAPI() dependency may differ from re-packed gradle api version that exis in Maven repository.