the faff around gradle 9 getting rid of `exec { }`...
# community-support
b
the faff around gradle 9 getting rid of
exec { }
is really annoying where is it documented what the conversion is? what am i supposed to do? https://github.com/search?q=%22exec+%7B%22+language%3Agradle&type=code there are 38,000 usages of
exec {
šŸ™„ 1
e
if it's in a task action, switch to Exec or use ExecOperations. if it's in lazy configuration, use ProviderFactory. if it's neither, then that's bad practice (and ProcessBuilder has always been there)
b
thanks for the comment. so this is the idea?
Copy code
tasks.register("...") {
  doLast {
    exec {
    }
    exec {
    }
  }
}
becomes
Copy code
def execOperations = services.get(ExecOperations)

tasks.register("...") {
  doLast {
    execOperations.exec {
    }
    execOperations.exec {
    }
  }
}
?
v
Not quite. •
services.
is not public API but internal, so if you use it it can break any time • you use a build script reference so if you try to use configuration cache it will also fail
āž• 1
v
This should work if you really need to stuff that logic into the build script:
Copy code
interface ExecOperationsProvider {
   @Inject
   ExecOperations getExecOperations()
}
tasks.register("...") {
   def execOperations = objects.newInstance(ExecOperationsProvider).execOperations
   doLast {
      execOperations.exec {
      }
      execOperations.exec {
      }
   }
}
but it might be better to make it a proper task class where you can inject the
ExecOperations
without that provider-trick
āœ… 1
b
okay, i would post this somewhere in the docs
e
I linked the docs that are effectively the same as Vampire's reply
b
i see the idea with the difference between exec for configuration and execution, i'm sure you considered`configurationOperations.exec` and
execOperations.exec
but it would have been nice if it were just the right exec based on the context, it almost always is related to the scope of where it is called
okay i guess they need to be much more discoverable
v
"you"? We are just users like you šŸ˜‰
b
lol thank you i didn't realize
you guys seemed like experts
v
We are
But still just users like you and not affiliated with Gradle
b
i really appreciate it
šŸ‘Œ 1
v
And no, it does not so much depend on the context, but on the usage and use-case
You could also use the provider-based on at execution phase, or the exec operations in a value source at configuration time
b
i see... so am i understanding this correctly - since many exec operations provide (such as version strings) and depend on values (such as files changing),... i can make gradle more aware of this using the new api?
i wish i could find the examples how