Sebastian Schuberth
02/18/2025, 5:38 PMval in Kotlin DSL) inside a Gradle convention plugin / precompiled script plugin, and access it from the project that applies the plugin?Martin
02/18/2025, 5:40 PMMartin
02/18/2025, 5:40 PMMartin
02/18/2025, 5:40 PMSebastian Schuberth
02/18/2025, 5:42 PMMartin
02/18/2025, 5:52 PMMartin
02/18/2025, 5:52 PMMartin
02/18/2025, 5:53 PMkotlin-dsl plugin, just the regular embedded-kotlin one but I don't think it should change anythingBenedikt Ritter
02/18/2025, 6:08 PMSebastian Schuberth
02/18/2025, 6:16 PMUsually your plugin would register an extension and that extension could expose a val or a provider of the value (to make it more idiomatic)True, but that's something I wanted to avoid to just quickly extract some common property that I set in all of my project to the convention plugin, for common use.
Martin
02/18/2025, 6:20 PMthe code inside a pre-compiled script plugin is wrapped into an apply(Project) method of a generated plugin classOooh that makes sense.
Martin
02/18/2025, 6:25 PMkotlin-dsl )Benedikt Ritter
02/18/2025, 6:52 PMproject.properties["name-of-the-prop"]Sebastian Schuberth
02/18/2025, 6:54 PMGabriel Feo
02/18/2025, 7:34 PMPhilip W
02/18/2025, 10:20 PMVampire
02/18/2025, 10:51 PM(also another reason to not use kotlin-dsl )
@Martin another? I'm not aware of any reason not to use
kotlin-dsl.
But actually all you answers here do not really match, as OP asked about precompiled script plugin and you said yes and you used it like that but also said you don't use kotlin-dsl but only embedded-kotlin, which means that you cannot even use Kotlin DSL precompiled script plugins.
And even if you never use precompiled script plugins - which basically are just syntactic sugar over a normal binary plugin - it still makes sense to use kotlin-dsl, as it not only enables Kotlin DSL precompiled script plugins, but also brings some other benefits like the kotlinDsl() dependency, and various compiler plugins with their configuration like the sam-with-receiver plugin for the Action methods and the assignment to Property `val`s plugin, ...Vampire
02/18/2025, 10:55 PMext / extra property. Those could be accessed directly from Groovy DSL or via by extra from Kotlin DSL.
Or you have some Kotlin object outside the precompiled script plugin where you set the value and can then retrieve it from or similar.Martin
02/18/2025, 11:28 PMkotlin-dsl because it fragments the ecosystem for little value IMO. Having to remember all the differences vs regular Kotlin is a lot of cognitive load. I would also argue that kotlinDsl() adds unecessary dependencies. All of that is personal preference so I won’t be dying on this hill but IIRC, there are also performance issues with them like https://github.com/android/nowinandroid/issues/39. Unless those were fixed recently?Martin
02/18/2025, 11:30 PMkotlin-dsl ?Martin
02/18/2025, 11:31 PMVampire
02/18/2025, 11:32 PMkoltin-dsl adds.
kotlinDsl() is the Gradle Kotlin DSL like many extension functions and so on.
And also the added Kotlin compiler plugins and so on.
Not using kotlin-dsl also fragements the ecosystem, as the Gradle code in plugins looks much different from the Gradle code in build scripts. 🙂Martin
02/18/2025, 11:34 PMMartin
02/18/2025, 11:35 PMthe Gradle code in plugins looks much different from the Gradle code in build scripts.There’s a lot more Kotlin code written for non Gradle scripts usage so I’d rather stick with that as much as possible
Vampire
02/18/2025, 11:36 PMVampire
02/18/2025, 11:36 PMMartin
02/18/2025, 11:36 PMMartin
02/18/2025, 11:37 PM