From d1f9f7a5251935e14afeabd050cd81e25bd912b4 Mon Sep 17 00:00:00 2001 From: BAStos525 Date: Wed, 16 Oct 2024 13:29:01 +0300 Subject: [PATCH] put sonar into subprojects 1 Signed-off-by: BAStos525 --- build.gradle | 81 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 8aec953b..a0e921c0 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ plugins { id 'maven-publish' id 'com.github.johnrengelman.shadow' version '8.1.1' id 'org.sonarqube' version "5.1.0.4882" - id 'jacoco' + // id 'jacoco' } allprojects { @@ -56,10 +56,6 @@ subprojects { group = 'jp.co.soramitsu.iroha2-java' version = 'git rev-parse --short HEAD'.execute().text.trim() - test { - useJUnitPlatform() - } - java { toolchain { languageVersion = JavaLanguageVersion.of(8) @@ -106,23 +102,77 @@ subprojects { dependsOn "${project.path}:processTestResources" dependsOn "${project.path}:compileTestKotlin" - executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec") - - sourceSets sourceSets.main - reports { xml.required = true html.required = true } + + def excludes = [ + '**/R.class', + '**/R$*.class', + '**/BuildConfig.*', + '**/Manifest*.*', + '**/*Test*.*', + 'android/**/*.*', + 'androidx/**/*.*', + '**/*$ViewInjector*.*', + '**/*Dagger*.*', + '**/*MembersInjector*.*', + '**/*_Factory.*', + '**/*_Provide*Factory*.*', + '**/*_ViewBinding*.*', + '**/AutoValue_*.*', + '**/R2.class', + '**/R2$*.class', + '**/*Directions$*', + '**/*Directions.*', + '**/*Binding.*' + ] + def kotlinClasses = fileTree(dir: "${project.projectDir}/build/classes", excludes: excludes) + + classDirectories.from = files([kotlinClasses]) + def sourceDirs = [ + "${project.projectDir}/src/main/java", + "${project.projectDir}/src/main/kotlin", + "${project.projectDir}/src/debug/java", + "${project.projectDir}/src/debug/kotlin" + ] + sourceDirectories.from = files(sourceDirs) + + executionData.from = files( + ["${project.buildDir}/jacoco/test.exec", "${project.buildDir}/jacoco/integrationTest.exec"] + ) } - tasks.named('testCoverage') { - // Add specific dependencies for tasks that weren't covered - mustRunAfter ":${project.path}:processTestResources" - mustRunAfter ":${project.path}:compileTestKotlin" - mustRunAfter ":${project.path}:test" + test { + useJUnitPlatform() + failFast = true + testLogging { + events "passed", "skipped", "failed" + } + reports { + junitXml.required = true + } + finalizedBy testCoverage } + // task testCoverage(type: JacocoReport) { + // // Ensure all necessary tasks are complete before running testCoverage + // dependsOn "${project.path}:test" + // dependsOn "${project.path}:processTestResources" + // dependsOn "${project.path}:compileTestKotlin" + + // executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec") + + // sourceSets sourceSets.main + + // reports { + // xml.required = true + // html.required = true + // } + // } + + sonar { properties { property "sonar.projectKey", "hyperledger:iroha-java" @@ -130,9 +180,12 @@ subprojects { property "sonar.projectName", "${project.group}:${rootProject.name}.${project.name}" property "sonar.sources", "${project.projectDir}/src/main/java" property "sonar.tests", "${project.projectDir}/src/test" + property "sonar.java.binaries", "${project.projectDir}/build/classes" + property "sonar.java.libraries", "${project.projectDir}/build/libs" property "sonar.java.test.binaries", "${project.projectDir}/build/test-results/test/binary" property "sonar.junit.reportPaths", "${project.projectDir}/build/test-results/test/" property "sonar.coverage.jacoco.xmlReportPaths", "${project.projectDir}/build/reports/testCoverage/*.xml" + property "sonar.exclusions", "${project.projectDir}/**/*.txt" } }