I’m using Caliper to run performance benchmarks. I’m creating a JavaExec-based task to run the “com.google.caliper.Runner” class, but I need to pass in a benchmark class name (for example “org.example.parsers.ParserBenchmark”). I’m not sure of the best way to do this. My first attempt was:
task bench(type: JavaExec, dependsOn: compileTestJava) {
…
benchmarkClass = rootProject.ext.properties.get(“bench_class”)
if (benchmarkClass == null) throw new AssertionError(“Set the ‘bench_class’ property.”)
main = ‘com.google.caliper.Runner’
args = [benchmarkClass, …]
}
The problem is that the “if (benchmarkClass = null)” check happens at configure time. So if I’m just compiling the project, it will fail saying that “bench_class” isn’t set. I want to make it so that “bench_class” is only checked if the ‘bench’ task is running.
(Though even if I get that working, my overall approach still seems messy. Does anybody know of a cleaner way to do this?)