Is there a way to suppress `Kotlin plugin should b...
# gradle
m
Is there a way to suppress
Kotlin plugin should be enabled before 'kotlin-kapt'
error message? I have gradle script like this:
Copy code
plugins {
    kotlin("kapt") version Versions.kotlin
}

subprojects {
    kapt {
        useBuildCache = true
    }
}
Basically, I want to automatically enable build cache on all projects. But since some projects are android and some are regular kotlin, I cannot apply any plugin in this root gradle script, I only need the kapt.
g
I would apply kapt plugin explicitly on every module where you need it
m
I do that already
but then I would have to copy paste this useBuildCache block to every submodule gradle file
g
Ah, I got what you want
m
which would clutter the scripts
g
you need another approach
project.plugins.withId(“kotlin-kapt”) { kapt { useBuildCache = true } }
m
but script still wouldn't compile, right?
g
or even better use it by type
m
since plugin would not be declared
g
You have to specify type
project.plugins.withType<KaptPlugin>
(not sure about class of KaptPlugin tho
But in general, you don’t need all this stuff
just set
kapt.useBuildCache=true
to your gradle.properties
😲 1
m
It's
Kapt3GradleSubplugin
thanks for both workarounds
t
another good way to do it that is more general is with
Copy code
project.pluginManager.withPlugin("com.android.application") {
      apply from: "${rootProject.projectDir}/gradle/defaultConfig.androidApp.gradle"
    }
that will detect the plugin having been applied and once the plugin.apply returns it will run your config block
I do this is our project so that all the library build files end up as just:
Copy code
plugins {
  `android-library`
}
dependencies {
  ...
}
same for
kotlin("jvm")
etc…
t
Copy code
plugins {
    kotlin("kapt") version Versions.kotlin apply false
}
g
apply false would disable Kotlin DSL type safe accessors and snippet above will be broken
t
Yeah... I got your point.