Is there any way to write a plugin in a standalone...
# general
m
Is there any way to write a plugin in a standalone repository using the pre-compiled plugin syntax? Gradle and it’s DSL try to remain relatively backward compatible. The problem is that the APIs underneath them don’t always do that. So compiling against, say the Android Gradle Plugin Api tends to lead to having to maintain multiple versions of a plugin, due to the underlying API changes. However, the kotlin DSL itself hasn’t actually changed. I’d love to be able to just do something like this in a conventions plugin. But i haven’t figured out how to do this. Instead i have to look for the real extension names (LibraryExtension, AppExtension) and work from there. And as those change over time, i have to keep updating my plugin, whereas the below syntax would (generally) not change.
Copy code
android {
   buildFeatures { 
       compose = true
   }
   ...
}
This is a slightly different question than asked above, as i’m trying to just use a more stable syntax within my plugin. I’ve already got the basics down, and it works, it’s just problematic as versions of AGP change.
e
if you're ok with it only being stringly-typed like the Groovy DSL, there is https://gradle.github.io/kotlin-dsl-docs/api/org.gradle.kotlin.dsl/kotlin.-any/with-groovy-builder.html
m
i’d prefer strict typing, just with the actual proper kotlin dsl.
e
if the underlying types change incompatibly you can't be type-safe across different versions in a single build
m
I can hit command-b on the android block in a regular build script and see the extension function that provides it, but for whatever reason, i can’t import that into my kotlin based plugin.
Copy code
package org.gradle.kotlin.dsl

...

/**
 * Configures the [android][com.android.build.gradle.LibraryExtension] extension.
 */
fun org.gradle.api.Project.`android`(configure: Action<com.android.build.gradle.LibraryExtension>): Unit =
    (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("android", configure)
message has been deleted
e
generated dsl extensions should be imported automatically if you're writing a precompiled script plugin which includes the plugin, otherwise they're simply not available
m
@ephemient yeah, unfortunately, i’m trying to build this as a standalone plugin that i can publish to a nexus repo and apply it to all our libraries (we have an app that’s very modularized and we want standardized build scripts, hence the need for the plugin). I really just want the syntax of the pre-compiled script plugin, but within a standalone plugin repository.
e
I don't quite understand - you can publish a precompiled script plugin - but if the Android plugin changes its API you're broken either way
m
@ephemient The kotlin DSL tends to stay the same across versions, even though the underlying classnames and stuff might change, That’s what i’m trying to insulate myself from. I’m having some success, but android studio isn’t really liking it very much and despite things working on the command line, it’s showing errors in there.