Three ways to get a task: `tasks["foo"]`, `tasks.n...
# getting-started
r
Three ways to get a task:
tasks["foo"]
,
tasks.named("foo").get()
,
tasks.getByName("foo")
. I guess the first is extra in Kotlin, because the language allows the
[]
syntax for
get
, but is there a difference between the second and third?
m
What's the type of
tasks
? Where is
named
and
getByName
coming from?
r
Not sure... it's at the top level of by build script. Maybe this is because I'm using Kotlin.
m
Ah, so it's the Gradle DSL?
r
TaskContainer
I think.
m
Sure, that's part of the Gradle DSL. Not the Kotlin stdlib. 😉
r
It looks like both
named
and
getByName
are defined in
org.gradle...
classes. One returns the task, and the other a "provider". Not sure what the purpose is.
m
You should look them up in the API doc
They both say they fail if there is no such named object, so I don't see a meaningful difference between the two. Maybe the return type difference matters more for some reason in Groovy.
s
A better place to ask is #gradle
or in the Gradle Community slack in the #kotlin-dsl channel
r
Ah, thanks. Duh, I didn't notice I posted in wrong channel.
n
getByName allows you to pass a type like so
Copy code
tasks.getByName<TaskType>("taskname") { 
  // configuration here
}