gradlekotlingroovy

How do I apply the Kotlin jvm plugin from another custom plugin?


I'm trying to integrate Kotlin into our build system, which uses custom plugins to encapsulate the set of plugins needed for a particular build archetype. Example:

import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.plugins.JavaPlugin
import {our internal Java path}.OurBasePlugin

class OurJavaPlugin implements Plugin<Project> {

    @Override
    void apply(Project project) {
        project.plugins.apply OurBasePlugin

        project.plugins.apply JavaPlugin
        project.plugins.apply GroovyPlugin
    }
}

I need need to do the same this for Kotlin, but I am stumped as to what plugin to import and apply:

import org.gradle.api.plugins.GroovyPlugin
import org.jetbrains.kotlin.[what goes here?]
import {our internal Java path}.OurBasePlugin

class OurKotlinPlugin implements Plugin<Project> {

    @Override
    void apply(Project project) {
        project.plugins.apply OurBasePlugin

        project.plugins.apply [what goes here?]
        project.plugins.apply GroovyPlugin
    }
}

Solution

  • org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin is the class you're looking for. Here is the example where they do a similar thing.

    import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
    
    class OurKotlinPlugin implements Plugin<Project> {
        @Override
        void apply(Project project) {
            project.plugins.apply KotlinPlatformJvmPlugin
        }
    }