Sonarqube plugin not reporting src from peer multimodule projects

sonarqube

(Gregory Gee) #1

I am having difficulties trying to get jacoco and sonarqube to get code coverage results from the code in the library projects that are used by the web service project. This is the basic layout of my Gradle mutli-module project.

  • parent
    • library project1
    • library project2
    • webService project

Gradle 2.13 and org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1-rc3

My parent project has the sonar properties in the build.gradle. I have an integrationTest task in the webService project. The webService project depends on the two library jar projects. The library projects have no integration test configuration. I can run my integration tests, but when I run sonarqube task, it is only reporting coverage for the webService project.

How can I get code coverage during integration tests for the dependent library project’s source code?

Each of the library project’s build.gradle looks like this. Is something missing to have jacoco and sonar scan this source?

buildscript {
  ext { springBootVersion = '1.4.1.RELEASE' }
  dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") }
}

apply plugin: 'spring-boot'
jar { archiveName = 'schema.jar' }

configurations {
  all*.exclude group: "org.slf4j", module: "slf4j-simple"
  all*.exclude group: "org.hibernate", module: "hibernate-entitymanager"
}

dependencies {
  compile('org.springframework.boot:spring-boot-starter-data-jpa')
  compile("org.eclipse.persistence:org.eclipse.persistence.jpa:2.6.4")
  compile("org.springframework:spring-orm")
  compile('org.springframework.boot:spring-boot-starter-web')
  compile("com.oracle.jdbc:ojdbc7:12.1.0.2")

  testCompile('org.springframework.boot:spring-boot-starter-test')
}
bootRepackage { enabled = false }

Has anyone been able to do this? I found this example code and it made a little difference I think.

// get source dirs for project dependencies
FileCollection getSonarSrcDirs(List projects) {
    Set srcDirs = sourceSets.main.java.srcDirs
    projects.each {
        def projDir = project(it).projectDir
        srcDirs.add("${projDir}/src/main/java")
    }
    return files(srcDirs)
}
sonarqube {
    properties {
        property "sonar.sources", getSonarSrcDirs([':library1',':library2'])        
    }
}

But when I run sonarqube, I get the following message.

File '/scratch/workspace/project/library1/src/main/java/Application.java' is ignored. It is not located in module basedir '/scratch/workspace/project/ws'.

Am I not allowed to have the dependent modules in a peer directory instead of a sub directory to the ws project folder?