Use Case:
OpenRewrite is a tool to performce large-scale code migrations/refactorings which leverages parsing Java/Groovy/Kotlin sources and performing modifications on them.
For Kotlin you can find the parsing code in KotlinParser
Now we also want to be able to properly parse build.gradle.kts files so we can extract method/type information, like e.g. for a given build.gradle.kts containing:
plugins {
java
}
We would want need the association of plugins to something like KotlinProjectScriptTemplate.plugins, etc.
From what I understand we can somehow configure SCRIPT_DEFINITIONS for the compiler, like:
compilerConfiguration.add(
ScriptingConfigurationKeys.SCRIPT_DEFINITIONS, ScriptDefinition.FromTemplate(
baseHostConfiguration = hostConfiguration,
template = classLoader.loadClass("org.gradle.kotlin.dsl.KotlinProjectScriptTemplate").kotlin,
contextClass = classLoader.loadClass("org.gradle.kotlin.dsl.KotlinProjectScriptTemplateCompilationConfiguration").kotlin
))
But its very hard to find a good example on how to actually use it.
Is there official documentation/examples on this, or how can we manage to do this properly?
Thanks and best regards ![]()