Using Gradle as a bootstrapper for programs

Sometimes your build has a dependency to some program during execution. For example, a TeX distribution to compile the documentation.

I’d like to use Gradle to bootstrap such programs globally on the running machine. This means: to download and cache it for reuse, even for other builds needing it. Just as the Gradle wrapper does with the Gradle distribution.

The idea is to use standard dependency management and the Gradle cache for this. However, the problem is that the source of the program is an archive which needs to be unpacked before it can be used. I don’t know how to synchronize the unpacked version of the dependency with the artifact dependency managed by Gradle.

Is this possible somehow? Can the use case of program bootstrapping be achieved in some other way? What is the best approach to the problem?