nuhkoca
06/10/2021, 4:14 PMprecompiled script
for child Gradle
scripts. How can I add another plugin in such file?
apply<LibraryCommonPlugin>()
configure<BaseExtension> {
defaultConfig {
...
}
}
What I’ve tried;
• to add plugins { kotlin("android") }
on top of file but didn’t work
• to configure like configure<PluginDependenciesSpecScope> { kotlin("android") }
on top of file but didn’t work
What do I need to do to get it to working?Vampire
06/10/2021, 4:51 PMnuhkoca
06/10/2021, 5:23 PMVampire
06/10/2021, 5:24 PMnuhkoca
06/10/2021, 5:27 PMnuhkoca
06/10/2021, 11:30 PMnuhkoca
06/10/2021, 11:34 PMnuhkoca
06/11/2021, 10:14 AMVampire
06/11/2021, 10:15 AMnuhkoca
06/11/2021, 10:17 AMVampire
06/11/2021, 10:57 AMVampire
06/11/2021, 10:58 AMVampire
06/11/2021, 11:06 AMgradlew help
works fine with it commented in.
Well, there is one point.
To generate type-safe accessors for precompiled Kotlin build scripts, Gradle takes the plugins
block, applies it to a dummy project, evaluates it and then checks which things were added for which it then generates the accessors.
kotlin("android")
requires that the android
extension is present.
You require this by the requirement to apply your precompiled script plugin after the com.android.application
plugin.
So the accessor generation fails how you do it, but the build still works, you just cannot use type-safe accessors in your precompiled script plugin and get an exception logged.
If you do
plugins {
id("com.android.application")
kotlin("android")
}
in your precompiled script plugin the android
extension is present even during type-safe accessor generation, so the logged exception goes away and you can use type-safe accessors.
You should then also be able to do android {
instead of configure<BaseExtension> {
as then the accessors for com.android.application
are also generated.nuhkoca
06/12/2021, 4:13 PMlibrary
and application
scripts that’s why I can’t apply com.android.application
or com.android.library
directly to it. But manually ,I can apply kotlin("android")
in each child script instead like so;
android-application.gradle.kts
plugins {
id("com.android.application")
kotlin("android")
id("android-defaults)
}
android-library.gradle.kts
plugins {
id("com.android.library")
kotlin("android")
id("android-defaults)
}
I just wanted to avoid repeating step here but seems it is not possible.Vampire
06/13/2021, 10:22 PMplugins
block, but don't use type-safe accessors, as the generation of them will fail. Additionally you have to ignore the exception that will be logged during the accessor generation, it does not affect the build if you don't use the accessors.
2. Don't apply the plugin using the plugins
block, but the legacy apply
method. You still can't use accessors from that plugin, as those are only generated for plugins applied in the plugins
block, but you also don't get the exception logged anymore.
3. Write another precompiled script plugin where you check with an if
either whether one of the Android plugins is already applied, or whether you are within the dummy project for accessor generation, and if so, apply one of the Android plugins, just to be able to apply the Kotlin Android plugin, then apply that plugin in your existing plugin too.Vampire
06/14/2021, 2:12 PMandroid
extensions, so that for the rest accessors can be generated.Vampire
06/14/2021, 11:59 PM