Archiving dependencies to disk as a local Maven repo

Howdy. I’m trying to figure out how to cache a copy of all my project’s dependencies to disk in Maven format. (Our CI server has a security policy that doesn’t allow fetching dependencies from the network.)

There’s a few examples out there of folks who are trying to cache all their dependencies with something like this:

task downloadDependencies() {
    from configurations.compile
    into "../third_party/compile"

However, this just gives me a flat file full of .jar/.aar files.

The problem with this is that it doesn’t work with my existing Maven-style dependency rules. Instead, I’d have to write a parallel set of build rules just for offline use. (And from testing, this can get particularly complicated… especially once Android .aar files and more complex dependency rules are involved.)

Instead, I’d much prefer to just register a local Maven repository that contains everything the build would need, and keep all my dependency rules untouched.

Is there any way to build this repository automatically?

How strict are you about haven the local repo in Maven format? There is the Ivypot plugin, but it stores it locally in an Ivy repo. You can control the file layout.