Hi all! I want to create convention plugins in sep...
# gradle
s
Hi all! I want to create convention plugins in separate folder. All is going ok except ‘android’ extension doesn’t appear until if I copy internal kotlin extension
Copy code
/**
 * Configures the [android][com.android.build.gradle.internal.dsl.BaseAppModuleExtension] extension.
 */
fun org.gradle.api.Project.`android`(configure: Action<com.android.build.gradle.internal.dsl.BaseAppModuleExtension>): Unit =
    (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("android", configure)
I’m talking about this ext
AS Chipmunk RC2
v
How / where do you write the convention plugin. Convention plugin just means you are defining some conventions in it, not how you write them. Script plugins, pre-compiled script plugins, binary plugins, Groovy DSL, Kotlin DSL, ...
s
Moved from a Precompiled Kotlin Script Plugin (
.gradle.kts
) to a Kotlin Plugin (
.kt
). And everything works. Thanks @handstandsam for example!
h
Awesome @Sanendak, glad you were able to use my open source repo as an example! Please 😄
1
s
Just to clarify. I wanted to use this extension outside app/library module. Turned up that .kt is better
🤷 1
h
Not sure I understand your use case, but these sort of plugins can be used on any modules.
s
I’ve created
build-logic
folder like on this repo. But cannot use
android
block in any
.kts
file 😕
v
It must be
*.gradle.kts
and you have to apply the Android plugin from its
plugins
block to get the accessors generated. But I thought you use binary plugins coming from
*.kt
files now.
That's why I asked for the details you refused to provide. ;-)
s
Originally I wanted to use
.gradle.kts
with
android
block (screenshot). Now i’m switched to .kt and using
project.extensions.getByName("android")
. I hope that now I was able to correctly explain the problem 😉
v
As I said, it will work with
android
block if you apply the corresponding Android plugin in the
plugins { ... }
block of the same precompiled script plugin. Getting the extension by Type or by name always works in both, precompiled script plugins, binary plugins, and everywhere else.