Created
November 21, 2020 18:50
-
-
Save bnorm/39118d6a6cdb25853882a84bf2ee3e95 to your computer and use it in GitHub Desktop.
Writing Your Second Kotlin Compiler Plugin - Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TemplateGradlePlugin : KotlinCompilerPluginSupportPlugin { | |
override fun apply(target: Project): Unit = with(target) { | |
extensions.create("template", TemplateGradleExtension::class.java) | |
} | |
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true | |
override fun getCompilerPluginId(): String = BuildConfig.KOTLIN_PLUGIN_ID | |
override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( | |
groupId = BuildConfig.KOTLIN_PLUGIN_GROUP, | |
artifactId = BuildConfig.KOTLIN_PLUGIN_NAME, | |
version = BuildConfig.KOTLIN_PLUGIN_VERSION | |
) | |
override fun getPluginArtifactForNative(): SubpluginArtifact = SubpluginArtifact( | |
groupId = BuildConfig.KOTLIN_PLUGIN_GROUP, | |
artifactId = BuildConfig.KOTLIN_PLUGIN_NAME + "-native", | |
version = BuildConfig.KOTLIN_PLUGIN_VERSION | |
) | |
override fun applyToCompilation( | |
kotlinCompilation: KotlinCompilation<*> | |
): Provider<List<SubpluginOption>> { | |
val project = kotlinCompilation.target.project | |
val extension = project.extensions.getByType(TemplateGradleExtension::class.java) | |
return project.provider { | |
listOf( | |
SubpluginOption(key = "string", value = extension.stringProperty.get()), | |
SubpluginOption(key = "file", value = extension.fileProperty.get().asFile.path), | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment