7.4x Upgrade Issue with testRuntimeClasspath

When upgrading from Gradle 7.3.3 → 7.4.1 or 7.4.2 our build starts failing with:

Could not resolve all dependencies for configuration ‘:my-module:testRuntimeClasspath’.
Value for metadata of project :my-module has not been calculated yet.

Gradle points to this line in {root}/my-module/build.gradle:

test {
    jvmArgs "-javaagent:${classpath.find { it.name.contains("jmockit") }}"
}

Any suggestions?

This line causes dependency resolution to occur too soon. It’s trying to pull values from the configured classpath of the test task while still in the configuration phase. There are technically jvmArgumentProviders that could help with deferring until later, but this is cleaner in a plugin than in the buildscripts.

You should be okay to defer pulling out the jmockit Java agent param until executing time by adding it in a task action with doFirst {...}. Up-to-date checking should still be fine as this value is being derived from an input that is considered.

Many thanks!

This solved the problem:

test {
    doFirst {
        jvmArgs "-javaagent:${classpath.find { it.name.contains("jmockit") }}"
    }
}