Understanding Gradle #24 - Kotlin DSL and Groovy DSL

Поділитися
Вставка
  • Опубліковано 16 вер 2024

КОМЕНТАРІ • 4

  • @romanpavliuk2301
    @romanpavliuk2301 Рік тому +4

    Thanks for the helpful video. I was struggling to migrate for several things mentioned in the video from Groovy to Kotlin

  • @Omega3131
    @Omega3131 9 місяців тому +1

    I tried using tasks.named("wrapper") { ... } to configure the wrapper task, but got an error. The way it's working is: task wrapper(type: Wrapper) { ... } What syntax is this? I'm using Groovy DSL BTW.

    • @jjohannes
      @jjohannes  8 місяців тому +1

      The approach looks correct. Which error did you get? If it is only an issue in the IDE, you can also define the type of the task as part of 'named':
      *tasks.named('wrapper', Wrapper) { ... }*
      *task wrapper(type: Wrapper) { ... }* is one of the "convenience" notations introduced in Gradle 1 for Groovy DSL. It's likely to be deprecated in the future. It is the same as doing *task.getByName('wrapper', Wrapper) { ... }* or (if the task does not exist) *task.create('wrapper', Wrapper) { ... }* . In your case, it might create the task if it does not yet exists for whatever reason, but that's probably not what you want. Which is one of the reasons I think this notation is a bit "too magical".

    • @Omega3131
      @Omega3131 8 місяців тому

      @@jjohannesUnderstood, thanks! The problems was that I was doing this under a subproject configuration instead of the parent.