This message was deleted.
# community-support
s
This message was deleted.
c
I don't get the question, replacing register by named I guess
👍 1
e
if it's registered by a plugin, there should be a generated accessor as well,
Copy code
tasks.runWithEnv {
    environment("XXXX", "YYY")
}
v
His problem is probably more that the Kotlin
run
function wins over the
tasks.run
accessor and so he cannot do
tasks.run { ... }
. But as Cristian said,
tasks.named<JavaExec>("run") { ... }
should work.
c
oh right thats one of the things i tried and it failed. did not think of the run function, thanks for pointing that out
e
you can rename to avoid the shadowing,
Copy code
import kotlin.run as run_
tasks.run { // now this works like tasks.named<JavaExec>("run") { ... }
v
Oh, that's a nice nasty trick, thanks, didn't think of that.
Or of course you can then also rename the
run
accessor to use
tasks.runTask { ... }
or similar I guess
e
also
tasks.run.configure { ... }
works regardless
❤️ 1
👍 2
c
cool, I changed it to
import kotlin.run as _
and thats what I’m going to use from now on
ok run.configure is even better because then i don’t have to add a comment to the import (and idea flags the import as unused)
v
and idea flags the import as unused
That 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.
c
right but I no longer report such minor idea bugs. 5 years ago I would have happily reported it. now I’m just happy when a refactoring does not destroy all my code
v
It's not actually in IntelliJ bug. It is a Kotlin IntelliJ Plugin bug (KTIJ), totall different team. 🙂
But ok, then I'll report it 🙂
👍 1
e
actually I wonder why it shadows, I would expect
fun TaskContainer.run()
to be more specific than
fun <T> T.run()
c
But ok, then I’ll report it
will probably be marked as duplicate of a 3 year old bug
v
Which one?
c
I have no idea 🙂 its just my hunch when bugs stay open for so long that any bug i could report is already reported multiple times
v
Happens from time to time, but then I at least know which to watch and vote for if I didn't find it by searching. 😄 And well, reporting issues is always worth it. For one if noone tells them, noone can fix it. And, I regularly get free all products pack for being such a gadfly :-D
c
yeah you are totally right. I currently have 28 bugs reported that are either open or “backlog”. only in the kotlin idea plugin
v
19 here, but I use Kotlin only for build logic 🙂
actually I wonder why it shadows, I would expect
fun TaskContainer.run()
to be more specific than
fun <T> T.run()
@ephemient I also wondered in the past, but actually it is logical. There is no
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.
If there would also be
fun TaskContainer.run()
, I guess it would win over
T.run
, so maybe a candidate for an improvement on Gradle side.
But that would probably be a heavily breaking change potentially.
1
Interestingly, explicitly importing
Copy code
import 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"
Copy code
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 { ... }
.
c
more issues to report!
v
indeed
I think my favorite for the future is to use
Copy code
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.run