This message was deleted.
# community-support
s
This message was deleted.
m
I have logic to skip tasks if they're not needed, but the task dependencies still execute. For example, if I have some configuration like so:
Copy code
test.onlyIf { false }
I would expect that directly invoking the
test
task skips its dependencies but I'm seeing the opposite behavior. Am I modeling this wrong, or am I understanding this wrong?
e
that's working as expected, it only skips that particular task's actions at execution time, not anything calculated to be part of the task graph during configuration
👍 1
https://docs.gradle.org/current/userguide/command_line_interface.html#sec:excluding_tasks_from_the_command_line will skip dependencies but I don't think there a way to do that inside gradle
v
onlyIf
is an executiontime check. So the dependency tasks could influence the outcome of this check, so they must be run as @ephemient described.
will skip dependencies but I don't think there a way to do that inside gradle
iirc you can actually do it inside the build, by modifying the start parameters object, but not at execution time, only at configuration time or maybe even just in the settings script or an init script, I don't fully remember.
e
yeah I haven't tried but if there's a way it would have to be pretty early in the build lifecycle
v
One could think so, but one would be wrong 🙂
I just tried, and
Copy code
gradle.startParameter.excludedTaskNames.add("check")
in a normal build script works just fine. It just has to be done during configuration phase, before the task graph is finalized.
m
Does that impact the configuration-cache at all? Could I do that logic conditionally, like:
Copy code
if (project.property("something") == true)
   // mess with the startParameter thing
v
You can do the logic conditionally
🙌 1
Whether it impacts CC, I'm not sure
👍 1
Or well, it will invalidate CC, because project properties are CC input
So if
something
changes, it should invalidate CC entry
m
Right, so I'm having a bit of trouble refactoring. I originally had something like this: 1. Find list of projects affected by a given code change 2. Store all of those in a
BuildService
3. Use
onlyIf
on tasks (i.e.
test
) to control whether or not they execute based on data in the
BuildService
But if
onlyIf
doesn't stop task dependencies from executing, then it seems I must use
gradle.startParameter.excludedTaskNames
. However, if I have to use that API, then the original logic I had doesn't work, right? Because that
excludedTasknames
stuff has to be done before the task graph is finalized
v
Exactly. Well, depends on whether you can do the "find list of projects" at configuration time. But maybe you should just not use the logic at all, but let Gradle decide what is necessary to execute. 🙂
Gradle is pretty good in avoiding unnecessary work
👍 1
m
It definitely is for sure! I'm working on a project though to tell Gradle not to build anything if a given code change wouldn't reasonably effect task success. Given this setup:
Copy code
Root build 
   platform-build-1
      platform specific modules...
   platform-build-2
   platform-build-3
   shared-build
      sharedModules...
Each
platform-build
has an `includeBuild("shared-build")`line as part of their settings. Sometimes, code is added to
shared
that doesn't affect every platform, i.e. it would only affect
platform-build-1/platform-build-2
and not
platform-build-3
. The
onlyIf
logic I have works pretty well - if a given code change doesn't affect
platform-build-3
, it won't for example, execute all tests in
platform-build-3
. We're doing this for a few reasons, one of which is some caching restrictions we're working through. I realize this is a bit overkill though!