I am registering a task and it is automatically ru...
# gradle
j
I am registering a task and it is automatically run when the IDE syncs. Every single time I press the sync button. When I run
gradlew build
, it doesn't run. I tried both,
register
and
create
, same problem. Is it a bug or is it the expected behavior?
m
The IDE Sync is not invoking a Gradle task directly, it's using the Gradle tooling API to inspect the build. There's no direct link between "Sync" and "build" (or tasks in general FWIW)
I'd love to have a Gradle plugin that creates a task that emulates what IntelliJ is doing but that seems very unlikely to happen
j
The task is changing files, and then when I sync the project, the files are changing too. It is a real problem
😬 1
I am going to check if there is an open issue about this
m
I get the impression that "Sync" sometimes calls "javaGenerating" tasks
(or maybe kapt)
But haven't really found a pattern there
t
as far as I know sync triggers all tasks creation, but not action execution
@Javier it will help if you could provide project to reproduce the issue
j
Mmm okay, basically I am publishing a precompiled plugin to maven central which is registering a task, and adding it to another project
I will add them later
v
You most likely do something wrong, like doing work in the configuration phase instead of execution phase or similar. But without you providing an MCVE here or in that issue, all is guesswork. And even if it were a bug, it would not be fixable without an MCVE.
j
it is a precompiled plugin applied to the root project which is registering a task which just use file().writeText(...)
v
Yep, exactly what I suspected and said.
You are doing the work at configuration time.
😑 1
So every time your task is configured your logic is done
You miss a
doFirst
or
doLast
j
ah okay
thank you 🙂
I didnt know I have to write to the file in doLast
v
Whatever you do outside of doLast or doFirst is done during configuration phase, every time your task is configured, whether it will be executed or not.
👍 1
j
@tapchicoma is it possible to I can close the issue in youtrack
1
t
please close
v
You cannot close as user, can you?
I never was able yet
Always had to let JB people do it
j
I can't, or I can't see how
If DefaultTask is used, it is necessary using doFirst and doLast too, no?
v
Everything in the
@TaskAction
method is in execution phase already
doFirst and doLast are only for ad-hoc tasks or to add actions to existing tasks
j
TIL, thank you 🙂