Uploaded image for project: 'Gradle'
  1. Gradle
  2. GRADLE-2795

Gradle locks the global script cache during the entire build, causing subsequent builds to fail if scripts change

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.13-rc-1

      Description

      For scripts included with "apply from" gradle uses the cache in user's home to keep compiled classes.
      Probably to ensure the same script content is applied throughout the build, a shared lock is kept on this cache for the time it runs.
      If a build detects the script has changed, it acquires an exclusive lock, updates the cache and goes back to a shared lock.
      However if there was another build running under the same user, it will fail after the default 1 minute timeout, due to the other build's shared lock.

      In practice this means a change to a shared script will cause all following builds to fail for a user, until all builds that were running during the change have finished.

      I can think of a couple of solutions:
      1. make the script's key in the cache a combination of path and file hash/date. A script will have multiple versions in the cache and each build will use the one it needs.
      2. copy the cached class(es) to the .gradle folder of the current build. A shared lock on the cache in user's home will only be kept for the short time of cloning required cache artefacts,
      3. ignore the cache if exclusive lock can not be acquired. Compile the script and use it only in the current build. This will slow down builds due to waiting and compiling but eventually the cache will be updated.

      When the scenario occurs, a GradleScriptException exception with this message is thrown :

      A problem occurred evaluating script.
      Could not open buildscript class cache for script 'http://.../?p=build-core;a=blob_plain;f=repository-utils.gradle;hb=HEAD' (/home/build/.gradle/caches/1.6/scripts/_p_build_core_a_blob_plain_f_r_4n9gdhqrjd4inp4c6jive7ql9c/DefaultScript/buildscript).
      Timeout waiting to lock buildscript class cache for script 'http://.../?p=build-core;a=blob_plain;f=repository-utils.gradle;hb=HEAD' (/home/build/.gradle/caches/1.6/scripts/_p_build_core_a_blob_plain_f_r_4n9gdhqrjd4inp4c6jive7ql9c/DefaultScript/buildscript). It is currently in use by another Gradle instance.
      Owner PID: unknown
      Our PID: 15314
      Owner Operation: unknown
      Our operation:
      Lock file: /home/build/.gradle/caches/1.6/scripts/_p_build_core_a_blob_plain_f_r_4n9gdhqrjd4inp4c6jive7ql9c/DefaultScript/buildscript/cache.properties.lock

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                melix C├ędric Champeau
                Reporter:
                forums Gradle Forums
              • Votes:
                43 Vote for this issue
                Watchers:
                46 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: