Hello, do you know if it is possible to apply Kotlin DSL scripts? applying `.gradle.kts` scripts wit...
j
Hello, do you know if it is possible to apply Kotlin DSL scripts? applying
.gradle.kts
scripts with
apply(from = "<file>.gradle.kts")
doesn't work for me (Gradle 6.5). However, errors happens only when the script relies on a plugin (it seems to work fine if no extra plugin is required). If someone has had the same issue I would appreciate your comments. Thanks!
o
c
You can apply arbitrary Kotlin scripts with the
apply(from = ...)
syntax and they will work fine, but you won’t be able to access anything from outside that script. Any plugins, etc. that are applied won’t be available to the main script that’s including it. Precompiled plugins are the way to go
1
j
Thanks for the information! I was applying Gradle helper scripts from a GitHub repository inside different projects... As I would need to publish those precompiled plugins I will stick to the
.gradle
ones for a while... Thanks again for the suggestion, I will migrate to precompiled plugins eventually
o
I don't quite get what you're saying -- are you retrieving these files from another GitHub repository? precompiled plugins are usually not published, they're local to a repository
j
Yes, I have Gradle helper scripts in a repo, and I use them from the Internet with:
apply(from = "<https://github.com/.../helper.gradle>")
from other projects (so I don't copy them locally)
e
Juanjo, applying remote Kotlin scripts work with the limitation pointed by Casey above. Note that using remote scripts means your build is subject to those scripts changing without much notice. It’s a bit like using dynamic versions. What happens if you need to use a previous version of your build? You might be ok with that, just one thing to keep in mind. Octavia, precompiled scripts can and are often published as regular binary Gradle plugin such as on the plugin portal.
j
Thanks @eskatos I will go that way… however, the versions I used are tagged along the project releases (the Gradle helpers are stored in a GitHub repository), so they stay stable 🙂
👍 1