Maven Java/Scala MultiModule Project Ignores Scala Sources

Hi all, I’m having difficulty with a Maven & Scala multi-module project that is being built in Azure DevOps and integrated to SonarCloud. I’m using the AzureDevops Tasks to auto-modify my pom.xml during CI as opposed to checking in these changes to my repo.

  • ALM used (Azure DevOps)
  • CI system used Azure DevOps
  • Languages of the repository Java/Scala

Scala code in this repo is built using net.alchim31.maven:scala-maven-plugin:3.2.2 and is a multi-module maven project. Scala code is unit tested using scalatest.

Sonarcloud properly identifies the multi-module structure, but is only identifying the Java and XML code, none of my scala code. Sonar isn’t clear on this, but do I need to add scoverage plugin before Sonar will pick up my scala files?

If you browse the Code tab of the project on SonarCloud, do you see the Scala files? If they were part of the specified sources during the scan with Maven, then they should be there.

I would also check the output of the command mvn sonar:sonar -Dsonar.scanner.dumpToFile=props.txt and look for lines containing sonar.sources=. For each module in the project, there should be a line containing comma-separated list of the source directories (typically src/main/java, and for the Scala files src/main/scala, I suppose). If you don’t see the Scala source directories there, then they won’t be analyzed.

One more thing. I assume the Scala plugin is registering additional source folders to the Maven model (to be confirmed). For our sonar plugin to “see” them, the analysis has to be run in the same reactor:

mvn package sonar:sonar

If you do that in two different steps, it will not work:

mvn package
mvn sonar:sonar

I forgot to update this for others having the same problem. Ultimately, I ended up using the add-source goal to the scala-maven-plugin so that the scala source files were available later for sonarcloud analysis.

<execution>
    <id>scala-sources</id>
    <goals>
        <goal>add-source</goal>
    </goals>
    <phase>process-sources</phase>
</execution>
3 Likes