2

I have a gradle project which applies the sonarqube gradle plugin, version 2.6.
I run it against my team's sonarqube server, version 6.4 (build 25310).

According to documentation, new versions of sonarqube accept the property sonar.junit.reportPaths instead of sonar.junit.reportsPath.

My build runs 2 test tasks: test and integrationTest. Each test task outputs its xml into a different directory: build/test-results/test and build/test-results/integrationTest respectively.
I configured the sonarqube plugin to pick up both these directories:

project.sonarqube {
     properties {
         property 'sonar.junit.reportsPath', ['build/test-results/test',
                                              'build/test-results/integrationTest']

         // configure additional integration test properties that seem to be required
         Collection<File> integrationTestSourceDirs = project.sourceSets.integrationTest.allJava.srcDirs.findAll { File dir -> dir.exists() }
         properties['sonar.tests'] += integrationTestSourceDirs
         Collection<File> integrationTestsClasses = project.sourceSets.integrationTest.output.classesDirs.files.findAll { File file -> file.exists() }
         properties['sonar.java.test.binaries'] += integrationTestsClasses
     }       
}

This does not work. In sonarqube UI I only see unit tests (from the test directory) and don't see any integration tests.
I made sure that my integrationTest directory contains valid test reports, and it does.

It seems like sonarqube still uses the old parameter sonar.junit.reportsPath (which by default is assigned by the gradle plugin with the value build/test-results/test). I can tell this because if I remove this parameter I don't see any unit tests at all in the UI. This is how I removed the old parameter:

project.sonarqube {
   properties {
        properties.remove("sonar.junit.reportsPath")
   }
}    

As a workaround, I configured my integrationTest task to put its output into the same directory as unit tests: build/test-results/test. After doing this, all tests, including integration tests are picked up by sonarqube, and I can see them all in the UI.

However, I would prefer to keep outputs of different test tasks in different directories.
Is the described behavior intentional, or is it a bug?

Doron Gold
  • 3,664
  • 4
  • 32
  • 44
  • Which version of the Java plugin in SonarQube are you using? – Vampire Nov 13 '17 at 15:06
  • 1
    And try setting the sonar property `sonar.scanner.dumpToFile` to some filename, then you will get the actual final properties dumped out to that file that are used by the analysis. If both properties are set, the new one should be used and a message about the deprecated one logged during execution. – Vampire Nov 13 '17 at 15:27
  • @Vampire in the dump file I see that the actual final properties are exactly what I configured. I also see these properties in the sonarqube UI under `Background Tasks` -> `Show Scanner Context`. I don't get a message about the old parameter being deprecated. I use sonarqube gradle plugin version 2.6. – Doron Gold Nov 13 '17 at 16:00
  • I asked about the Java plugin version in SonarQube, not about the Gradle plugin version. – Vampire Nov 13 '17 at 16:02
  • @Vampire my sonarqube server has SonarJava version 4.10.0.10260 installed. – Doron Gold Nov 13 '17 at 16:09

1 Answers1

2

Your SonarJava plugin is too old. The new property is only available from 4.11 on. In 4.10 only the old property is evaluated, so the new one is ignored. The Gradle plugin just sets the properties. The evaluation happens in the code that is downloaded from the SonarQube server and thus ignored.

Vampire
  • 35,631
  • 4
  • 76
  • 102