After updating gradle to 8.2.1 problem with configuration cache occurs
Asked Answered
K

2

3

After updating gradle to 8.2.1 problem with configuration cache occurs:

This is my error:

Configuration cache problems found in this build.

1 problem was found storing the configuration cache.
- Build file 'app/build.gradle.kts': external process started 'git rev-parse --verify --short HEAD'
  See https://docs.gradle.org/8.2.1/userguide/configuration_cache.html#config_cache:requirements:external_processes

this problem occurs with code:

val gitCommitHash = "git rev-parse --verify --short HEAD".runCommand(workingDir = rootDir)

then try to assign
versionNameSuffix = "-QA ($gitCommitHash)"

I saw solution with gradle.properties but it doesn't work.:

org.gradle.unsafe.configuration-cache=true
Koziara answered 22/2, 2024 at 15:6 Comment(0)
L
1

I think configuration cache is not worth the trouble. Works for me in Android Studio but not on build server (where I really don't give a shit about the duration of a build).

I just deactivated it and it's running again.

gradle.properties:

org.gradle.configuration-cache=false
Loanloanda answered 27/3, 2024 at 8:19 Comment(0)
A
1

The issue arises because starting an external process during the configuration phase is not supported with the configuration cache enabled. This is detailed in the Gradle user guide for configuration cache requirements: Configuration Cache Requirements. To resolve the issue of starting an external process 'git rev-parse --verify --short HEAD' during configuration time in Gradle, you can use the following solution which aligns with the requirements and restrictions outlined in the Gradle documentation. The solution involves creating a custom ValueSource that can be used to obtain the Git commit hash without violating the configuration cache constraints.

  1. Create a custom ValueSource class to obtain the Git commit hash:
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters
import org.gradle.process.ExecOperations
import java.nio.charset.Charset
import javax.inject.Inject

abstract class GitCommitValueSource implements ValueSource<String, ValueSourceParameters.None> {

    @Inject
    abstract ExecOperations getExecOperations()

    String obtain() {
        ByteArrayOutputStream output = new ByteArrayOutputStream()
        execOperations.exec {
            it.commandLine "git", "rev-parse", "--verify", "--short", "HEAD"
            it.standardOutput = output
        }
        // Return the output as a trimmed string to exclude any trailing newline characters
        return new String(output.toByteArray(), Charset.defaultCharset()).trim()
    }
}

def gitCommitProvider = providers.of(GitCommitValueSource::class) {}
// Get the git commit hash (e.g., "1abcdef"), already trimmed of any trailing newline characters
def gitCommit = gitCommitProvider.get()
  1. Use the custom ValueSource in your build script to set the versionNameSuffix:
android {
    // your android configuration

    defaultConfig {
        versionNameSuffix = "-QA ($gitCommit)"
    }
}

For more details, refer to the Gradle Configuration Cache Requirements.

Abysm answered 28/5, 2024 at 8:35 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.