I'm trying to build a Docker image for developing an Android app. I have an image that installs the JDK, Android SDK + NDK.
When I run the image and run the gradle wrapper (gradlew), the wrapper downloads the latest Gradle, and then all the dependencies of my app, so I see messages like:
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.4/gradle-3.1.4.pom
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.1.4/builder-3.1.4.pom
...
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre8/1.2.0/kotlin-stdlib-jre8-1.2.0.pom
Download https://jcenter.bintray.com/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom
...
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.4/gradle-3.1.4.jar
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-core/3.1.4/gradle-core-3.1.4.jar
Etc.
Due to the nature of Docker containers, every time I run a new container, it will have to download all these dependencies again, as if it's the first time. (I could re-use a container, but I'd prefer everyone who uses this image not have to download these files; and using a fresh container every time is desirable for other reasons.) So I'd like to get them "baked into" the Docker image. What's the best way to do so?
One idea is to add instructions to the Dockerfile to copy in the source code of my project and do a build (and then remove the project files from the image). However, this seems tricky (we should ignore files that are not tracked by .git) and wasteful (why actually do an entire build; I just want these files downloaded and put into the appropriate location).
Another option is to do a build, get all those URLs out of the build output, figure out where they are supposed to go on disk (not sure how to do that), and then add instructions in the Dockerfile to manually copy them into place. But this seems like a lot of work, and will require manual updating when my app dependencies change.
It seems like there should be a way to copy in the gradle wrapper and a minimal set of gradle build files and ask it to "just restore dependencies", but I haven't been able to find such a target. Is there a way to do that?