3

Hi I'm trying to use the trick described here to allow continuous building inside docker containers. The trick works fine when I open two separate terminals on my host machine, but fails when used in docker containers.

docker-compose.yml

  build_server:
    image: gradle:6.3.0-jdk8
    working_dir: /home/gradle/server
    volumes:
      - ./server:/home/gradle/server
    command: ["gradle", "build", "--continuous", "-x", "test"]

  server:
    image: gradle:6.3.0-jdk8
    working_dir: /home/gradle/server
    volumes:
      - ./server:/home/gradle/server
    ports:
      - 8080:8080
    depends_on:
      - build_server
    restart: on-failure
    command: ["gradle", "bootRun"]

The error message I got from server container:

server_1         | FAILURE: Build failed with an exception.
server_1         |
server_1         | * What went wrong:
server_1         | Gradle could not start your build.
server_1         | > Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
server_1         |    > Could not create service of type ChecksumService using BuildSessionScopeServices.createChecksumService().
server_1         |       > Timeout waiting to lock checksums cache (/home/gradle/server/.gradle/checksums). It is currently in use by another Gradle instance.
server_1         |         Owner PID: unknown
server_1         |         Our PID: 31
server_1         |         Owner Operation: unknown
server_1         |         Our operation:
server_1         |         Lock file: /home/gradle/server/.gradle/checksums/checksums.lock

It looks like gradle has added locks on local cache files and prevents bootRun task from being run in the other container. However, the trick works fine when I run the tasks in two terminals on my host machine, or when I only run the build_server container and run bootRun on host terminal. I wonder why it doesn't work inside docker containers. Thanks for helping in advance!

Paul Zhu
  • 61
  • 1
  • 3
  • I'm pretty sure the daemon in each container need to be able to communicate with one another if you mount the same gradle home folder or project folder (where the lock files reside). But I don't know what ports are used and how to make it work, if it is even possible... – Bjørn Vester Jul 16 '20 at 08:25
  • @BjørnVester Thanks for the info. In that case, maybe I should run both tasks in one single container? – Paul Zhu Jul 16 '20 at 08:46
  • Yes, that will probably work. – Bjørn Vester Jul 16 '20 at 08:56

1 Answers1

2

Found a workaround by setting a different project cache dir for the server container. i.e. replace the command with the following

command: ["gradle", "bootRun", "--project-cache-dir=/tmp/cache"]

Might not be the best solution but it does circumvent the problem caused by gradle's lock.

Paul Zhu
  • 61
  • 1
  • 3