在当前的这个示例中:
123
# 控制台输入命令
$ ./gradlew bootRun
项目已集成JUnit 5和Mockito测试框架,并使用Jacoco进行代码覆盖率分析。
运行所有测试:
# 运行所有单元测试
$ ./gradlew test
查看测试报告:
# 测试报告位置
$ open build/reports/tests/test/index.html
项目使用Jacoco插件生成代码覆盖率报告:
# 生成代码覆盖率报告
$ ./gradlew jacocoTestReport
# 查看覆盖率报告
$ open build/reports/jacoco/index.html
运行综合质量检查(包括测试、覆盖率和代码风格):
# 运行所有代码质量检查
$ ./gradlew codeQualityCheck
项目已整合 Checkstyle 来确保代码质量和一致性。Checkstyle 是一个可以帮助 Java 程序员遵守编码标准的开发工具。
您可以使用以下命令运行 Checkstyle 检查:
# 运行 Checkstyle 检查
$ ./gradlew checkstyleMain
# 生成 Checkstyle HTML 报告
$ ./gradlew checkstyleReport
生成的 HTML 报告位于 build/reports/checkstyle/main.html。
Checkstyle 配置文件位于 config/checkstyle/checkstyle.xml,默认使用基于 Google Java 代码规范的配置。您可以根据项目需求修改此文件来自定义检查规则。
主要检查规则包括:
gradle/wrapper/gradle-wrapper.properties 中的如 distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 下载 Gradle Wrapper 而下载慢。gradle/wrapper/gradle-wrapper.properties 中的 distributionUrl 改为 distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.6-bin.zip
参考: Gradle 下载地址。repositories { mavenLocal() maven { url "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/" } mavenCentral() }
allprojects { repositories { mavenLocal() maven { url "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/" } mavenCentral() } }
当您的 JAVA 工程比较大时可以配置一下 Gradle 使用的 JVM 内存大小,让构建更加高效,请参考 https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory
gradle.properties 中的 org.gradle.jvmargs 将 Xmx 和 Xms 调整到一个合适的值。123