build.gradle 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Licensed to Elasticsearch under one or more contributor
  3. * license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright
  5. * ownership. Elasticsearch licenses this file to you under
  6. * the Apache License, Version 2.0 (the "License"); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. buildscript {
  20. repositories {
  21. maven {
  22. url 'https://plugins.gradle.org/m2/'
  23. }
  24. }
  25. dependencies {
  26. classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
  27. }
  28. }
  29. apply plugin: 'elasticsearch.build'
  30. // build an uberjar with all benchmarks
  31. apply plugin: 'com.github.johnrengelman.shadow'
  32. // have the shadow plugin provide the runShadow task
  33. apply plugin: 'application'
  34. archivesBaseName = 'elasticsearch-benchmarks'
  35. mainClassName = 'org.openjdk.jmh.Main'
  36. // never try to invoke tests on the benchmark project - there aren't any
  37. check.dependsOn.remove(test)
  38. // explicitly override the test task too in case somebody invokes 'gradle test' so it won't trip
  39. task test(type: Test, overwrite: true)
  40. dependencies {
  41. compile("org.elasticsearch:elasticsearch:${version}") {
  42. // JMH ships with the conflicting version 4.6 (JMH will not update this dependency as it is Java 6 compatible and joptsimple is one
  43. // of the most recent compatible version). This prevents us from using jopt-simple in benchmarks (which should be ok) but allows us
  44. // to invoke the JMH uberjar as usual.
  45. exclude group: 'net.sf.jopt-simple', module: 'jopt-simple'
  46. }
  47. compile "org.openjdk.jmh:jmh-core:$versions.jmh"
  48. compile "org.openjdk.jmh:jmh-generator-annprocess:$versions.jmh"
  49. // Dependencies of JMH
  50. runtime 'net.sf.jopt-simple:jopt-simple:4.6'
  51. runtime 'org.apache.commons:commons-math3:3.2'
  52. }
  53. compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
  54. // enable the JMH's BenchmarkProcessor to generate the final benchmark classes
  55. // needs to be added separately otherwise Gradle will quote it and javac will fail
  56. compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"])
  57. compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
  58. forbiddenApis {
  59. // classes generated by JMH can use all sorts of forbidden APIs but we have no influence at all and cannot exclude these classes
  60. ignoreFailures = true
  61. }
  62. // No licenses for our benchmark deps (we don't ship benchmarks)
  63. dependencyLicenses.enabled = false
  64. thirdPartyAudit.excludes = [
  65. // these classes intentionally use JDK internal API (and this is ok since the project is maintained by Oracle employees)
  66. 'org.openjdk.jmh.profile.AbstractHotspotProfiler',
  67. 'org.openjdk.jmh.profile.HotspotThreadProfiler',
  68. 'org.openjdk.jmh.profile.HotspotClassloadingProfiler',
  69. 'org.openjdk.jmh.profile.HotspotCompilationProfiler',
  70. 'org.openjdk.jmh.profile.HotspotMemoryProfiler',
  71. 'org.openjdk.jmh.profile.HotspotRuntimeProfiler',
  72. 'org.openjdk.jmh.util.Utils'
  73. ]
  74. shadowJar {
  75. classifier = 'benchmarks'
  76. }
  77. // alias the shadowJar and runShadow tasks to abstract from the concrete plugin that we are using and provide a more consistent interface
  78. task jmhJar(
  79. dependsOn: shadowJar,
  80. description: 'Generates an uberjar with the microbenchmarks and all dependencies',
  81. group: 'Benchmark'
  82. )
  83. task jmh(
  84. dependsOn: runShadow,
  85. description: 'Runs all microbenchmarks',
  86. group: 'Benchmark'
  87. )