Implementing a gradle task that modifies the build.gradle(.kts) file

Hi Gradle Forum, we’re writing a gradle task ‘updateVersions’ that updates the versions of several dependencies and BOMs by modifying the build.gradle.kts file directly. We then set this as an dependency for the ‘test’ and ‘build’ tasks.

This leads to an error when resolving dependencies during those ‘test’ and ‘build’ tasks.

Is modifying the build.gradle.kts inside of a task a bad decision?
Is there a way to force a gradle re-sync during the execution of a gradle task?


I would expect that the change simply does not affect the currently running execution. The build scripts are first compiled and then evaluated and then the tasks executed. Maybe you would instead just want to use version ranges, maybe combined with the setting to publish resolved versions and eventually with dependency locking to get reproducible builds and only actually update the used versions at will.