How can I publish an aar to maven using gradle kot...
# android
d
How can I publish an aar to maven using gradle kotlin dsl? The android docs only give instructions for Groovy... https://developer.android.com/studio/build/maven-publish-plugin
v
And what is your problem with translating it to Kotlin DSL? The principle should be the same, just a little bit different in Syntax details
d
I don't have any idea where to find the
components.release
mentioned... another one of Groovy's magic tricks...
v
If there is no static accessor, then use the verbose variant:
components.named("release")
d
Thanks! And how do I translate
Copy code
release(MavenPublication) { .. }
?
In the PublicationContainer
Is it:
Copy code
create("release", MavenPublication::class.java) {
             ...   
            }
? It's hard to know what the Android plugin does for you, and what still needs to be done...
v
I'd use the generic variant
Copy code
create<MavenPublication>("release") {
Nicer to read
d
Oh.. so `
Copy code
components["java"]
needs to be
Copy code
components["release"]
? the thing is I tried the instructions there, but they didn't seem to work on Android... and the Android ones don't show kts... googling gave me articles and examples from 2019... or 2017.. What does that key used in components represent here? The created publication, or something Android provides? The gradle docs say:
Currently 3 types of component are supported: 'components.java' (added by the JavaPlugin), 'components.web' (added by the WarPlugin) and
components.javaPlatform
(added by the JavaPlatformPlugin).
v
Oh.. so `
components["java"]
needs to be
components["release"]
?
Why? The gradle docs say:
 Currently 3 types of component are supported: 'components.java' (added by the JavaPlugin), 'components.web' (added by the WarPlugin) and
components.javaPlatform
(added by the JavaPlatformPlugin).
I guess the Android plugin adds that component but due to that there is not static accessor and you have to use the
named
method
d
The named method doesn't return a
SoftwareComponent
expected by
from()
...
So I though that components can just be used as a Map implementation to retrieve what the Android plugin provides...
v
components.named("release")
is from the lazy api, it gives you a
Provider<SoftwareComponent>
if you need the
SoftwareComponent
, either get it from the provider or right away use
components.getByName("release")
or as you said
components["release"]
should also work
d
Thanks alot, it's working now ­čśâ! I guess this takes a bit of getting used to...