diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index c07ea60..2a1e964 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -30,7 +30,7 @@ jobs: key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Build and analyze - run: ./gradlew build sonar --info + run: ./gradlew test sonar --info env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/build.gradle b/build.gradle index d947d4b..ec5a348 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id 'org.springframework.boot' version '3.1.1' id 'io.spring.dependency-management' version '1.1.0' id "org.sonarqube" version "4.2.1.3168" + id 'jacoco' } group = 'everymeal' @@ -17,6 +18,8 @@ sonar { property 'sonar.language', 'java' property 'sonar.sourceEncoding', 'UTF-8' property "sonar.exclusions", "**/*Application*.java" + property "sonar.java.coveragePlugin", "jacoco" + property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/jacoco/test/jacocoTestReport.xml' } } @@ -36,4 +39,52 @@ dependencies { tasks.named('test') { useJUnitPlatform() + outputs.dir snippetsDir + finalizedBy 'jacocoTestReport' +} +ext { + snippetsDir = file('build/generated-snippets') +} +jacocoTestReport { + reports { + xml.required = true + html.required = true + } + + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, exclude: [ + "**/*Application*", + "**/config/*" + ]) + })) + } + + finalizedBy 'jacocoTestCoverageVerification' +} +jacocoTestCoverageVerification { + violationRules { + rule { + enabled = true // rule을 on/off + element = "CLASS" // class 단위로 rule 체크 + limit { // 라인 커버리지 최소 80% 충족 + counter = "LINE" + value = "COVEREDRATIO" + minimum = "0.80".toBigDecimal() + } + limit {// 빈 줄 제외한 코드 라인수 최대 1000라인으로 제한한다. + counter = "LINE" + value = "TOTALCOUNT" + maximum = "1000.0".toBigDecimal() + } + } + } + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, exclude: [ + "**/*Application*", + "**/config/*" + ]) + })) + } }