1. Gradle

如果是gradle项目, 在build.gradle文件中添加jmh的依赖 (有梯子好办事)

  1. plugins {
  2. id 'java'
  3. }
  4. allprojects {
  5. repositories {
  6. maven { url 'https://maven.aliyun.com/repository/jcenter' }
  7. maven { url 'https://maven.aliyun.com/repository/google' }
  8. maven { url 'https://maven.aliyun.com/repository/central' }
  9. maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
  10. }
  11. }
  12. dependencies {
  13. implementation 'org.openjdk.jmh:jmh-core:1.33'
  14. annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.33'
  15. }

2. Maven

如果你的项目是maven项目,直接添加依赖

  1. <dependency>
  2. <groupId>org.openjdk.jmh</groupId>
  3. <artifactId>jmh-core</artifactId>
  4. <version>1.33</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.openjdk.jmh</groupId>
  8. <artifactId>jmh-generator-annprocess</artifactId>
  9. <version>1.33</version>
  10. <scope>provided</scope>
  11. </dependency>