Skip to content

Commit

Permalink
Sonar task must depend on jacoco report task (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
jskov authored Mar 9, 2024
1 parent 03715e6 commit 3d9f3e8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/dk/mada/style/configurators/SonarConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.plugins.quality.Checkstyle;
import org.gradle.api.plugins.quality.CheckstylePlugin;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.testing.jacoco.plugins.JacocoPlugin;
import org.gradle.testing.jacoco.tasks.JacocoReport;
import org.sonarqube.gradle.SonarExtension;
import org.sonarqube.gradle.SonarTask;

Expand Down Expand Up @@ -40,15 +43,22 @@ public SonarConfigurator(Project project, SonarConfiguration sonarConfig) {
/**
* Configures the sonarqube extension.
*
* @param se the spotless extension
* @param se the sonarqube extension
*/
public void configure(SonarExtension se) {
logger.info("dk.mada.style configure sonar");

TaskContainer taskContainer = project.getTasks();

// Make sonar depend on checkstyle tasks (we want sonar to run last)
taskContainer.withType(SonarTask.class, sonar -> taskContainer.withType(Checkstyle.class, sonar::dependsOn));
// Make sonar depend on some other check tasks (we want sonar to run last)
project.afterEvaluate(p -> taskContainer.withType(SonarTask.class, sonar -> {
if (project.getPlugins().hasPlugin(CheckstylePlugin.class)) {
taskContainer.withType(Checkstyle.class, sonar::dependsOn);
}
if (project.getPlugins().hasPlugin(JacocoPlugin.class)) {
taskContainer.withType(JacocoReport.class, sonar::dependsOn);
}
}));

Map<String, String> inputProps = project.getProperties().entrySet().stream()
.filter(e -> !e.getKey().equals("dk.mada.style.sonar.enabled"))
Expand Down

0 comments on commit 3d9f3e8

Please sign in to comment.