build.gradle 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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:2.0.4'
  27. }
  28. }
  29. apply plugin: 'elasticsearch.build'
  30. // order of this seciont matters, see: https://github.com/johnrengelman/shadow/issues/336
  31. apply plugin: 'application' // have the shadow plugin provide the runShadow task
  32. mainClassName = 'org.openjdk.jmh.Main'
  33. apply plugin: 'com.github.johnrengelman.shadow' // build an uberjar with all benchmarks
  34. // Not published so no need to assemble
  35. tasks.remove(assemble)
  36. build.dependsOn.remove('assemble')
  37. archivesBaseName = 'elasticsearch-benchmarks'
  38. test.enabled = false
  39. dependencies {
  40. compile("org.elasticsearch:elasticsearch:${version}") {
  41. // JMH ships with the conflicting version 4.6. This prevents us from using jopt-simple in benchmarks (which should be ok) but allows
  42. // us to invoke the JMH uberjar as usual.
  43. exclude group: 'net.sf.jopt-simple', module: 'jopt-simple'
  44. }
  45. compile "org.openjdk.jmh:jmh-core:$versions.jmh"
  46. compile "org.openjdk.jmh:jmh-generator-annprocess:$versions.jmh"
  47. // Dependencies of JMH
  48. runtime 'net.sf.jopt-simple:jopt-simple:4.6'
  49. runtime 'org.apache.commons:commons-math3:3.2'
  50. }
  51. compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked,-processing"
  52. // enable the JMH's BenchmarkProcessor to generate the final benchmark classes
  53. // needs to be added separately otherwise Gradle will quote it and javac will fail
  54. compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"])
  55. forbiddenApis {
  56. // classes generated by JMH can use all sorts of forbidden APIs but we have no influence at all and cannot exclude these classes
  57. ignoreFailures = true
  58. }
  59. // No licenses for our benchmark deps (we don't ship benchmarks)
  60. dependencyLicenses.enabled = false
  61. dependenciesInfo.enabled = false
  62. thirdPartyAudit.excludes = [
  63. // these classes intentionally use JDK internal API (and this is ok since the project is maintained by Oracle employees)
  64. 'org.openjdk.jmh.profile.AbstractHotspotProfiler',
  65. 'org.openjdk.jmh.profile.HotspotThreadProfiler',
  66. 'org.openjdk.jmh.profile.HotspotClassloadingProfiler',
  67. 'org.openjdk.jmh.profile.HotspotCompilationProfiler',
  68. 'org.openjdk.jmh.profile.HotspotMemoryProfiler',
  69. 'org.openjdk.jmh.profile.HotspotRuntimeProfiler',
  70. 'org.openjdk.jmh.util.Utils'
  71. ]
  72. shadowJar {
  73. classifier = 'benchmarks'
  74. }
  75. runShadow {
  76. executable = new File(project.runtimeJavaHome, 'bin/java')
  77. }
  78. // alias the shadowJar and runShadow tasks to abstract from the concrete plugin that we are using and provide a more consistent interface
  79. task jmhJar(
  80. dependsOn: shadowJar,
  81. description: 'Generates an uberjar with the microbenchmarks and all dependencies',
  82. group: 'Benchmark'
  83. )
  84. task jmh(
  85. dependsOn: runShadow,
  86. description: 'Runs all microbenchmarks',
  87. group: 'Benchmark'
  88. )