#Troubleshooting Gradle build caching

1 messages · Page 1 of 1 (latest)

slate bear
#

A barebone Kotlin Gradle project takes 3 minutes to build, with no apparent caching.

    def get_test_container(self) -> Container:
        """
        Gradle 8.7 crashes on ARM devices: https://github.com/gradle/gradle/issues/24875
        To work around it we uninstall libstd++ and dependents as suggested in
        https://github.com/gradle/gradle/issues/24875#issuecomment-1783751649
        """
        build_cache = dag.cache_volume('build')
        gradle_cache = dag.cache_volume('build')
        return (
            dag.container().from_(BUILD_IMAGE)
            .with_mounted_cache(f"{GRADLE_PATH}/build", build_cache)
            .with_mounted_cache(f"{GRADLE_PATH}/.gradle", gradle_cache)
            .with_directory(GRADLE_PATH, self.src_dir, include=["src/", "*gradle*"],
                            exclude=["dagger/", "build/", ".gradle/"])
            # .with_mounted_directory(GRADLE_PATH, self.src_dir, owner="gradle:gradle")
            .with_workdir(GRADLE_PATH)
            .with_exec(['apk', 'del', 'libstdc++', 'binutils', 'mercurial'])    # workaround
            .with_exec(['gradle', 'buildFatJar', '--no-daemon'])
        )

What am I doing wrong? Is there an example to study? Any way I can troubleshoot on my own?

cold granite
#

You may need to add "exclude" patterns to your dagger.json if you have files inside your module that change frequently. At minimum you can add (assuming "source": ".", otherwise prefix the right subdir):

  "exclude": [
    ".venv",
    "sdk"
  ]

An example: https://github.com/helderco/daggerverse/blob/357dfd7f97eae9a62a2a13454b48cb7c69c44e34/linguist/dagger.json#L4-L8

If you're passing directories via function arguments, you may need to use views to filter them: https://github.com/dagger/dagger/pull/6857. An example: https://github.com/dagger/dagger/blob/338b405399f6872453fde8ee1002febe07a4119c/dagger.json#L6-L16 (see usage in https://github.com/dagger/dagger/tree/main/ci#readme).