Slackbot
09/22/2022, 10:11 PMCristianGM
09/22/2022, 10:28 PMephemient
09/23/2022, 5:37 AMtasks.runWithEnv {
environment("XXXX", "YYY")
}
Vampire
09/23/2022, 11:01 AMrun
function wins over the tasks.run
accessor and so he cannot do tasks.run { ... }
. But as Cristian said, tasks.named<JavaExec>("run") { ... }
should work.Christoph Sturm
09/23/2022, 12:13 PMephemient
09/23/2022, 12:17 PMimport kotlin.run as run_
tasks.run { // now this works like tasks.named<JavaExec>("run") { ... }
Vampire
09/23/2022, 12:18 PMVampire
09/23/2022, 12:18 PMrun
accessor to use tasks.runTask { ... }
or similar I guessephemient
09/23/2022, 12:19 PMtasks.run.configure { ... }
works regardlessChristoph Sturm
09/23/2022, 12:19 PMimport kotlin.run as _
and thats what I’m going to use from now onChristoph Sturm
09/23/2022, 12:21 PMVampire
09/23/2022, 12:28 PMand idea flags the import as unusedThat I'd recommend to report as bug to the KTIJ project on youtrack.jetbrains.com. If you rename one thing to move it out of the way, that classifies for me as used. If you remove it, the code does no longer compile.
Christoph Sturm
09/23/2022, 12:29 PMVampire
09/23/2022, 12:31 PMVampire
09/23/2022, 12:31 PMephemient
09/23/2022, 12:32 PMfun TaskContainer.run()
to be more specific than fun <T> T.run()
Christoph Sturm
09/23/2022, 12:33 PMBut ok, then I’ll report itwill probably be marked as duplicate of a 3 year old bug
Vampire
09/23/2022, 12:40 PMChristoph Sturm
09/23/2022, 12:43 PMVampire
09/23/2022, 12:57 PMChristoph Sturm
09/23/2022, 12:59 PMVampire
09/23/2022, 1:11 PMVampire
09/23/2022, 1:24 PMactually I wonder why it shadows, I would expect@ephemient I also wondered in the past, but actually it is logical. There is noto be more specific thanfun TaskContainer.run()
fun <T> T.run()
fun TaskContainer.run()
.
There is `val TaskContainer.`run`: TaskProvider<org.gradle.api.tasks.JavaExec>` .
And there is operator fun <T> NamedDomainObjectProvider<T>.invoke(action: T.() -> Unit)
.
These combined make tasks.run { ... }
work (with renamed kotlin.run
) which actually is tasks.run.invoke { ... }
(which is also a working alternative).
tasks.run { ... }
(in package kotlin
) is directly fun <T, R> T.run(block: T.() -> R): R
.
Due to that it wins as it is only one step.Vampire
09/23/2022, 1:26 PMfun TaskContainer.run()
, I guess it would win over T.run
, so maybe a candidate for an improvement on Gradle side.Vampire
09/23/2022, 1:26 PMVampire
09/23/2022, 1:33 PMimport org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.run
also makes tasks.run { ... }
configure the task, but you need to import both for it to work.
And more interestingly, if you only have the "unused"
import kotlin.run as _
and do a reformat with optimize imports,
IJ inserts all used org.gradle.kotlin.dsl
functions as explicit imports.
And if you then reformat again, it throws out again all imports except for the two necessary for tasks.run { ... }
.Christoph Sturm
09/23/2022, 1:35 PMVampire
09/23/2022, 1:44 PMVampire
09/23/2022, 1:48 PMimport org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.run