Unfortunately the build DSL usage is missing from the Shared Build Services documentation. You want to use Task.usesService
.
def myBuildService = gradle.sharedServices.registerIfAbsent( 'myService', BuildService ) {
maxParallelUsages = 1
}
tasks.withType( com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask ).configureEach {
usesService( myBuildService )
}
NOTE: I used configureEach
to take advantage of task configuration avoidance, it is not a required component of the build service solution.