Resolving dependency on gtest from testSuite fails

I’m trying to build googletest from source:

build.gradle

subprojects {
model {
    toolChains {
        clang(Clang)
    }
    platforms {
        'osx_x86-64' {
            architecture 'x86_64'
            operatingSystem 'osx'
        }
        ... // others
    }
}
}

gtest/build.gradle

apply plugin: 'cpp'

model {
  components{
    gtest(NativeLibrarySpec) {
      targetPlatform 'osx_x86-64'
      sources {
        cpp {
          source {
            srcDirs 'src'
            include 'gtest-all.cc'
          }
          exportedHeaders {
            srcDirs 'include'
          }
        }
      }
      binaries.all {
        cppCompiler.define 'GTEST_IMPLEMENTATION_', '1'
      }
    }
  }
}

(sorry for spacing inconsistency)

lib/build.gradle

...
testSuites {
    withType(GoogleTestTestSuiteSpec) {
        sources {
            cpp {
                lib project: ':gtest', library: 'gtest'
            }
        }
    }
}

But when I try to enumerate the tasks:

$ ./gradlew lib:tests
...
:lib:tasks FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lib:tasks'.
> No shared library binary available for library 'gtest' with [flavor: 'default', platform: 'osx-x86_64', buildType: 'debug']
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED

But,

$./gradlew gtest:components
...
:gtest:components
------------------------------------------------------------
Project :gtest
------------------------------------------------------------
Native library 'gtest'
----------------------
Source sets
    C++ source 'gtest:cpp'
        srcDir: src
        includes: gtest-all.cc
Binaries
    Shared library 'gtest:sharedLibrary'
        build using task: :gtest:gtestSharedLibrary
        buildType: build type 'debug'
        flavor: flavor 'default'
        targetPlatform: platform 'osx_x86-64'
        tool chain: Tool chain 'clang' (Clang)
        shared library file: build/libs/gtest/shared/libgtest.dylib
    Static library 'gtest:staticLibrary'
        build using task: :gtest:gtestStaticLibrary
        buildType: build type 'debug'
        flavor: flavor 'default'
        targetPlatform: platform 'osx_x86-64'
        tool chain: Tool chain 'clang' (Clang)
        static library file: build/libs/gtest/static/libgtest.a
Note: currently not all plugins register their components, so some components may not be visible here.
BUILD SUCCESSFUL