Skip to content

Instantly share code, notes, and snippets.

@mrbald
Last active November 7, 2024 22:11
Show Gist options
  • Save mrbald/7bbb5113c3164d5243314da8c28649a1 to your computer and use it in GitHub Desktop.
Save mrbald/7bbb5113c3164d5243314da8c28649a1 to your computer and use it in GitHub Desktop.
JMH gradle without plugin for multi-module projects
...
subprojects {
...
apply plugin: 'java'
apply plugin: 'scala'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets.main {
java.srcDirs = ['src/main/java']
scala.srcDirs = ['src/main/scala']
scala.include '**/*.*'
}
sourceSets.test {
java.srcDirs = ['src/test/java']
scala.srcDirs = ['src/test/scala']
scala.include '**/*.*'
}
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_source_sets
sourceSets {
jmh {
java.srcDirs = ['src/jmh/java']
scala.srcDirs = ['src/jmh/scala']
resources.srcDirs = ['src/jmh/resources']
compileClasspath += sourceSets.main.runtimeClasspath
}
}
dependencies {
...
jmhImplementation 'org.openjdk.jmh:jmh-core:1.27'
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.27'
}
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
task jmh(type: JavaExec, dependsOn: jmhClasses) {
main = 'org.openjdk.jmh.Main'
classpath = sourceSets.jmh.compileClasspath + sourceSets.jmh.runtimeClasspath
// To enable the built-in stacktrace sampling profiler
// args = ['-prof', 'stack']
}
// to make sure benchmarks always get compiled
classes.finalizedBy(jmhClasses)
}
...
@austinzh
Copy link

austinzh commented Nov 7, 2024

@mrbald I found the annotationProcessor not working for scala but only for java. Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment