Gradle 2.9: binaries.withType no longer work - alternatives?

Hi,

currently I migrate a c/c++ project from Gradle 2.5 to 2.9. At following code in the script gradle outputs the error:

Could not find property ‘binaries’ on task ‘:buildReleaseUnittestExecutable’.

The code in the script is:

task buildReleaseUnittestExecutable {
dependsOn binaries.withType(NativeExecutableBinary).matching {
it.buildable && it.buildType.equals(buildTypes.release) && it.targetPlatform.name.equals(coI686.PLATFORM)
}
mustRunAfter buildPreparation
}

Hmm, the release notes of 2.9 point that “The binaries container is no longer accessible as a project extension” - is this the reason. If yes, what is the alternative?

best regards
Martin

The binaries container is only accessible form within the model { } block. So you’ll have to do this with a model rule.

model {
    tasks {
        buildreleaseUnittestExecutable(Task) {
            dependsOn $.binaries.withType(NativeExecutableBinary).matching {
                it.buildable && it.buildType.equals(buildTypes.release) && it.targetPlatform.name.equals(coI686.PLATFORM)
            }
            mustRunAfter 'buildPreparation'

        }
    }
}