An idiomatic solution would look like this:
configurations {
api
}
dependencies {
api 'somegroup:someArtifact:someVersion'
}
task extractApi(type: Sync) {
dependsOn configurations.api
from { // use of closure defers evaluation until execution time
configurations.api.collect { zipTree(it) }
}
into "$buildDir/api/"
}