Be able to specify file types to be analyzed with SonarqubeScanner for Maven

Hi,

If I’ve not misunderstood, SonarqubeScanner for Maven analyze only *.java et *.xml files by default.
Also, it analyze all the files located in the project, filtering them by the previous mentioned types.

To analyze other types of files, like *.sql for example, we have to override default sourcePath properties.

I don’t understand the logic here. Overriding the sourcePath properties have a lot more impact than just be able to analyze all kinds of files.

Why there isn’t a property like “sonar.files.type” to be able to just override the kind of files to analyze without changing the sourcePath behaviour ?

Clément.

For my knowledge it is not true. By default it scans only pom.xml and all files in src/main/java.

If you want to scan everything - just specify in top (main) pom.xml file:

<properties>
    <sonar.sources>pom.xml,src/main/**</sonar.sources>
</properties>

All pom.xml and all files in src/main in all modules will be scanned.

Hi,

thank you for your reply !

I’m not sure about the default sonar.sources value.

Still, it seems weird to me to need to change the sources target directory to force sonar to analyze another kind of files.
I would prefer an other property.

The default is pom.xml,src/main/java, so setting sonar.sources is the only way to do it (I believe you don’t keep *.sql in src/main/java).

Hi,
As @agabrys explained we analyze by default the source folders as configured in Maven.
For regular maven projects, it’s going to be src/main/java and src/test/java. We also add the pom.xml file to it. Note that this is entirely depend on your maven project and the plugins you use. Some plugins might change these. For example, if you use groovy, the groovy plugin will add src/main/groovy and if sonar runs afterwards it will pick it up.

If you have sources in other directories - and we know this is not uncommon - you just need to override the default value with sonar.sources. All files with all extensions in the source foders will be analyzed (you just need to have in SonarQube a analyzer that can support a certain language).