Update Lockfiles For A Single Dependency

We’re using version locking, and trying to update lockfiles across several configurations. The problem is that the recommended classes task is only updating one of our lockfiles.

Basically, when we run:

./gradlew classes --update-locks mygroup:myproj

The only files getting updated right now is compile.lockfile, but this dependency is in several other classpaths.

When running;

./gradlew dependencies --write-locks

All dependencies are updated, including this project’s dependencies. As a workaround right now, we just iterate through and “undo” all the other projects that get updated. But that’s very manual and not what we want.

I’ve attempted to create a task to do this, but I can’t figure out to filter out just this project, i.e.,

        tasks.register("updateAProjectLocks") {
            doFirst {
                require(gradle.startParameter.isWriteDependencyLocks)
            }
            doLast {
                configurations.filter { it.isCanBeResolved }.forEach { configuration ->
                    configuration.withDependencies
                }
                configurations.filter { it.isCanBeResolved }.forEach { configuration ->
                    configuration.files(/* I have no idea */)
                }
            }
        }

Is this the right way to go about this? Or is there some wrinkle to my configuration I need to consider.

OK, so it looks like my original command should just be

./gradlew dependencies --update-locks mygroup:myproj

This was a little confusing because the user guide says “use the classes” task which actually doesn’t seem to work like I’d expect: https://docs.gradle.org/current/userguide/dependency_locking.html#selectively_updating_lock_state_entries

1 Like