I am trying to improve the build time of Hibernate ORM by using a parallel build, but since we are using a shared database for tests, I am running into issues when two test tasks of different projects run in parallel.
I read that this could be solved by using a shared build service and setting maxParallelUsage to 1 which I tried, but now my build fails, saying:
Cannot query the value of task ‘:hibernate-hikaricp:test’ property ‘databaseService’ because it has no value available.
I am using a custom plugin that defines the build service:
public class HibernateBuildPlugin implements Plugin<Project> {
private static final Logger log = Logging.getLogger( HibernateBuildPlugin.class );
@Override
public void apply(Project project) {
project.getGradle().getSharedServices().registerIfAbsent(
"db",
DatabaseService.class,
spec -> {
spec.getMaxParallelUsages().set( 1 );
}
);
}
}
And a simple build service:
public abstract class DatabaseService implements BuildService<BuildServiceParameters.None> {
}
In the main build, I register the plugin and custom task like the following:
I’d love to hear about this also. The docs on shared build services imply that this should work, but it does not in my experience either. To access such a service, my tasks always have to look it up
I was of the impression that this happens automatically. It also seems that the maxParallelUsages does not work properly. I still see test tasks being executed in parallel. Is this supposed to work?
I agree that this could be better documented.
In the section Registering a build service, example 3 shows the download task’s server property being set to the registered provider and there’s a small blurb after the example:
The plugin registers the service and receives a Provider<WebService> back. This provider can be connected to task properties to pass the service to the task.
It’s very easy to miss these subtle details and probably needs some improvement.
Currently there is not. IIUC, the build service class and the parameter object determine a build service uniquely. This means you would need to qualify the build service with its parameters in the task, which is currently not possible.
Great to know, thanks. Do you have an example somewhere that shows how the maxParallelUsages is supposed to work exactly? It’s not having any effect in our experiments. How is a “usage” registered/unregistered?
Maybe I missed some tests, but it looks like all the integration tests around this capability use the DSL and there’s no tests using annotated properties.
Side note; org.gradle.api.services.BuildServiceParameters should probably be added to the automatic imports like org.gradle.api.services.BuildService is.