At work I use Docker for development. This is done primarily to have a consistent development environment. Source code is edited in the host machine (using IDEA, in my case) and made available to the container via a shared volume.
We’re presently moving our build script from Ant to Gradle. As the first step, we’ve installed Gradle in the docker image, and shared ~/.gradle between the host and the container. I am able to execute gradle assemble inside the container to build code. Gradle starts a daemon when I run the command.
This works, but presents a problem when I edit code using IDEA. IDEA uses Gradle (Gradle tooling API) to build, but that means a daemon running in the host, outside the container. This in turn means locks, and having to do gradle --stop from the container once in a while.
Given the above premise, is it possible to share the Gradle daemon between the container and the host? For comparison SSH agent requests are forwarded to the docker container using the - SSH_AUTH_SOCK=/ssh-agent environment variable trick (see https://gist.github.com/d11wtq/8699521 for more). This enables me to run SSH commands from within the container without requiring the keys to be shared with the container.
Not sure if this counts as “progress”, but here’s what I have done so far.
Share the Gradle home directory between host and container (~/.gradle in my case)
Turn Gradle daemon off using $GRADLE_HOME/gradle.properties
Instruct IDEA to build using Gradle, pointing to the (shared) GRADLE_HOME
This has addressed most of my woes, bar one:
IDEA invokes Gradle when build.gradle.kts is modified. This locks several files under GRADLE_HOME. The locks disappear, but only eventually after the process died naturally. I’m not able to execute Gradle commands from within the container until that happens. In extremis I had to kill the Gradle process running the host.
Thank you so much for the infor @egmanoj, great info!
Is it just me or is a bit weird that there’s no solution to this problem OR more people interested in a solution. i have a hard time believing we are the only once hitting this.