@@ -8,6 +8,15 @@ plugins {
88 java
99 id(" io.freefair.lombok" ) version " 8.0.1" // Lombok plugin for Gradle
1010 id(" com.adarshr.test-logger" ) version " 4.0.0"
11+ id(" jacoco" )
12+ id(" org.sonarqube" ) version " 6.3.1.5724" // Use the latest version
13+ }
14+
15+ sonar {
16+ properties {
17+ property(" sonar.projectKey" , " conorheffron_shoopingcart-java" )
18+ property(" sonar.organization" , " conorheffron" )
19+ }
1120}
1221
1322repositories {
@@ -80,7 +89,7 @@ dependencies {
8089}
8190
8291group = " com.siriusxm.example.cart"
83- version = " 1.0.7 -RELEASE"
92+ version = " 1.0.8 -RELEASE"
8493description = " shoppingcart"
8594java.sourceCompatibility = JavaVersion .VERSION_21
8695
@@ -103,3 +112,42 @@ tasks {
103112 options.compilerArgs.add(" -parameters" ) // Optional: Enables parameter names in reflection
104113 }
105114}
115+
116+ tasks.withType<JacocoReport > {
117+ dependsOn(tasks.withType<Test >()) // Ensure tests run before generating the report
118+
119+ reports {
120+ xml.required.set(true ) // Enable XML report generation
121+ html.required.set(true ) // Enable HTML report generation
122+ csv.required.set(false ) // Disable CSV report generation
123+ }
124+
125+ // Configure the source sets for coverage
126+ val sourceSets = project.extensions.getByType< org.gradle.api.tasks.SourceSetContainer > ()
127+ sourceDirectories.setFrom(sourceSets[" main" ].allSource.srcDirs)
128+ classDirectories.setFrom(
129+ fileTree(" ${buildDir} /classes/java/main" ) {
130+ exclude(" **/generated/**" ) // Exclude generated code if necessary
131+ }
132+ )
133+ executionData.setFrom(fileTree(buildDir) {
134+ include(" **/jacoco/test.exec" ) // Include JaCoCo execution data
135+ })
136+ }
137+
138+ // Optional: Add a custom task to aggregate coverage reports for multi-module projects
139+ tasks.register<JacocoReport >(" jacocoAggregateReport" ) {
140+ dependsOn(subprojects.map { it.tasks.withType<Test >() })
141+
142+ reports {
143+ xml.required.set(true )
144+ html.required.set(true )
145+ }
146+
147+ val executionDataFiles = subprojects.flatMap { subproject ->
148+ subproject.fileTree(subproject.buildDir) {
149+ include(" **/jacoco/test.exec" )
150+ }
151+ }
152+ executionData.setFrom(executionDataFiles)
153+ }
0 commit comments