Hello :wave: I have a plugin that generates :kotli...
# gradle
d
Hello 👋 I have a plugin that generates K source code that is added to the main source set. Since the source code has to be compiled, for convenience I also configured the tasks to be finalized by
compileKotlin
/`compileTestKotlin` tasks. This works great for the regular JVM builds but blows up on the Android builds as those tasks don't exist and instead we have variants (e.g.
compileDebugKotlin
). Since I'm not familiar with Android ecosystem was wondering whether anyone here got some suggestions on • how to detect whether plugin is applied on Android project? (check for
android
extension?) • how to get all the variants? (get all tasks of compile kotlin type and then apply crude filter looking for
test
in the name?) • do I need to add generated sources to different source sets based on variants? • anything else that I might be missing?
d
👍 looks like I need to add some additional dependency for those android imports (
import com.android.build.gradle.BaseExtension
)
m
Yes, but you can make it a compile time dependency as the code path for Android won’t be executed if plugins are not available
👍 1
t
note that 'kotlin-andorid' is applied eagerly and it should be fixed in
1.5.30
release: https://youtrack.jetbrains.com/issue/KT-46626 With this release 'kotlin-android' will do configuration only when some of android plugins is applied
👀 1
a
Probably you can use something like that
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
    if ("Test" in name) return@configureEach
    // do something
}
d
so I tried adding the android build tools dependency as a compile only but it blows up with "unable to create decorated class"
com/android/build/gradle/api/BaseVariant
changing dependency to implementation does resolve the issue 🤷
fyi reason for above is due to https://github.com/gradle/gradle/issues/8411