Use a task for dependency locking


(Xinchao Zhang) #1

I am wondering if it is possible to use a gradle task for dependency locking rather than relying on the --write-locks command line parameter?

What I come up with at the moment is to run another command line command inside a task:

task lockDependencies {
    './gradlew dependencies --write-locks'.execute()

    'git add /gradle/dependency-locks'.execute()
} 

I will then make my release task depend on lockDependencies so that dependency lock is generated and committed automatically when release task runs.

The approach does feel a bit weird though. Please let me know if there is a more straightforward way.

Thanks


(Rob Fletcher) #2

I’d also really like this. I want to create a nightly job on CircleCI that updates locks, runs tests and commits the result if successful.


(Stefan M.) #3

The documentation shows an task which can be used (instead of the dependencies task).

But adding it to a VCS (and commiting it) is a whole new thing and can be archived like you did.
From my point of view there is nothing wrong using git add /gradle/dependency-locks'.execute().


(Xinchao Zhang) #4

Thanks. But I think the task in the documentation is not really doing the locking part. It is just a custom task which will result in all dependencies being resolved. The actual locking is still going to be trigger by --write-locks. If you look at the assertion in the doFirst:

assert gradle.startParameter.writeDependencyLocks

If I understand it correctly, it asserts that the task must be invoked in the form of

gradle resolveAndLockAll --write-lock