144 lines
4.0 KiB
Groovy
144 lines
4.0 KiB
Groovy
/*
|
|
* Copyright 2020, OpenTelemetry Authors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
|
|
/*
|
|
* This file should be imported in the top-level Gradle project.
|
|
* To add JMH microbenchmarks to any sub-project simply create 'src/jmh/java'
|
|
* and if required 'src/jmh/resource'. This JMH Gradle script will check for
|
|
* this sourceset, and will add tasks if it exists, and build any benchmarks.
|
|
*
|
|
* Running benchmarks can be done either through gradle using the task runJMH,
|
|
* or by downloading the created artifact and required dependencies.
|
|
*
|
|
* To use Gradle to download the benchmark for a specific version you can use
|
|
* a basic Gradle build file like the following.
|
|
*
|
|
* apply plugin: 'java'
|
|
*
|
|
* repositories {
|
|
* ...
|
|
* }
|
|
*
|
|
* dependencies {
|
|
* compile(group: 'GROUP', name: 'NAME', version: 'VERSION')
|
|
* compile(group: 'GROUP', name: 'NAME', version: 'VERSION', classifier: 'jmh')
|
|
* }
|
|
*
|
|
* task copyDependencies(type: Copy) {
|
|
* into 'execute'
|
|
* }
|
|
*
|
|
* task setup {
|
|
* dependsOn copyDependencies
|
|
* }
|
|
*
|
|
* $ gradle setup
|
|
* $ java -jar execute/group-name-version-jmh.jar
|
|
*/
|
|
|
|
sourceSets {
|
|
jmh {
|
|
java.srcDir 'src/jmh/java'
|
|
resources.srcDir 'src/jmh/resources'
|
|
compileClasspath += main.output
|
|
runtimeClasspath += main.output
|
|
}
|
|
}
|
|
|
|
def benchmarksAvailable = sourceSets.jmh.java.getFiles().any { f -> f.exists() }
|
|
|
|
dependencies {
|
|
jmhCompile 'org.openjdk.jmh:jmh-core:1.23'
|
|
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.23'
|
|
}
|
|
|
|
configurations {
|
|
jmhCompile {
|
|
extendsFrom compile
|
|
}
|
|
|
|
jmhImplementation {
|
|
extendsFrom implementation
|
|
extendsFrom jmhCompile
|
|
}
|
|
|
|
jmh {
|
|
extendsFrom runtime
|
|
extendsFrom jmhCompile
|
|
}
|
|
}
|
|
|
|
compileJmhJava {
|
|
enabled benchmarksAvailable
|
|
options.compilerArgs = compileJava.options.compilerArgs
|
|
options.fork = compileJava.options.fork
|
|
options.forkOptions = compileJava.options.forkOptions
|
|
}
|
|
|
|
task jmhRun(type: JavaExec) {
|
|
enabled benchmarksAvailable
|
|
description 'Run JMH benchmark(s). Use the property jmhFilter to set benchmark filtering regex.'
|
|
group 'Verification'
|
|
classpath = sourceSets.jmh.runtimeClasspath
|
|
main = 'org.openjdk.jmh.Main'
|
|
// Allows users to filter JMH benchmarks using a regex
|
|
mkdir("${project.buildDir}/results")
|
|
args "--rf", "json", "--rff", "${project.buildDir}/results/results.json"
|
|
args project.findProperty("jmhFilter") ?: ''
|
|
}
|
|
|
|
task jmhJar(type: Jar) {
|
|
dependsOn = ['compileJmhJava']
|
|
|
|
enabled benchmarksAvailable
|
|
description 'Generate executable JMH benchmark JAR, if any benchmarks exists.'
|
|
group 'Build'
|
|
classifier "jmh"
|
|
doFirst {
|
|
manifest {
|
|
attributes('Main-Class': 'org.openjdk.jmh.Main', 'Class-Path': ([jar.archiveFileName.get()] + configurations.runtimeClasspath.files.collect { it.getName() }).join(' '))
|
|
}
|
|
}
|
|
from {
|
|
(configurations.jmhRuntimeClasspath.files + configurations.runtimeClasspath.files).collect { it.isDirectory() ? it : zipTree(it) }
|
|
} {
|
|
exclude 'META-INF/*.SF'
|
|
exclude 'META-INF/*.DSA'
|
|
exclude 'META-INF/*.RSA'
|
|
exclude 'log4j.properties'
|
|
}
|
|
from (sourceSets.jmh.output + sourceSets.main.output)
|
|
}
|
|
|
|
artifacts {
|
|
if (benchmarksAvailable) {
|
|
archives jmhJar
|
|
}
|
|
}
|
|
|
|
publishing {
|
|
publications {
|
|
mavenJava(MavenPublication) {
|
|
if (benchmarksAvailable) {
|
|
artifact jmhJar {
|
|
classifier "jmh"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|